How to remove borders from cells in a range in Excel using VB net

0 votes

Aim: To get rid of borders if any in the cells of range.

I have :

Dim range As Excel.Range = sheet.Range("A2:K100")
For Each cell In range
    // Some cells in the Range has borders
    // How to remove borders from cells in the range
Next cell
Jan 5, 2023 in Others by Kithuzzz
• 38,000 points
1,840 views

1 answer to this question.

0 votes
range.Borders(Excel.XlBordersIndex.xlEdgeLeft).LineStyle = Excel.XlLineStyle.xlLineStyleNone
range.Borders(Excel.XlBordersIndex.xlEdgeRight).LineStyle = Excel.XlLineStyle.xlLineStyleNone
range.Borders(Excel.XlBordersIndex.xlEdgeTop).LineStyle = Excel.XlLineStyle.xlLineStyleNone
range.Borders(Excel.XlBordersIndex.xlEdgeBottom).LineStyle = Excel.XlLineStyle.xlLineStyleNone
range.Borders(Excel.XlBordersIndex.xlInsideHorizontal).LineStyle = Excel.XlLineStyle.xlLineStyleNone
range.Borders(Excel.XlBordersIndex.xlInsideVertical).LineStyle = Excel.XlLineStyle.xlLineStyleNone

Removes the borders around the cells and between cells (via xlInsideHorizontal and xlInsideVertical). If you expect diagonal borders, include xlDiagonalDown and xlDiagonalUp.

Okay, the above code was very verbose. The following should do it too:

For Each border in range.Borders
    border.LineStyle = Excel.XlLineStyle.xlLineStyleNone
Next

See: http://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.borders.aspx

answered Jan 5, 2023 by narikkadan
• 63,600 points

Related Questions In Others

0 votes
1 answer

Using Visual Basic to pull data from within a range to use in an Excel function

Use AVERAGEIFS instead of the full range. ...READ MORE

answered Jan 14, 2023 in Others by narikkadan
• 63,600 points
498 views
0 votes
1 answer

How to automatically get a specified range of data from Excel to XML in VBA

Range method works, always identify the sheet ...READ MORE

answered Mar 18, 2023 in Others by narikkadan
• 63,600 points
832 views
0 votes
1 answer

Unable to import data in excel from another website using VB code

Replace : Set ieTable = ieDoc.all.Item("report-table") With: Set ieTable = ...READ MORE

answered Sep 21, 2022 in Others by narikkadan
• 63,600 points
781 views
0 votes
1 answer

Excel-VBA - How to identify Target range (more than 1 cell) is deleted in a Worksheet_Change function?

You misunderstand the purpose of the function ...READ MORE

answered Sep 23, 2022 in Others by narikkadan
• 63,600 points
3,720 views
0 votes
1 answer

Program that works in all version of excel

Knowing that all of your users will ...READ MORE

answered Sep 24, 2022 in Others by narikkadan
• 63,600 points
626 views
0 votes
1 answer

How to add Header and Footer in excel with vb.net?

This code will work: Imports Microsoft.Office.Interop Private Sub Button1_Click(sender ...READ MORE

answered Dec 10, 2022 in Others by narikkadan
• 63,600 points
744 views
0 votes
1 answer

Releasing COM-Object not necessary?

This place has infamously poor Office COM ...READ MORE

answered Feb 24, 2023 in Others by narikkadan
• 63,600 points
671 views
0 votes
1 answer

Retrieve epay.info Balance with VBA and Excel

This code should log you in, provided ...READ MORE

answered Sep 5, 2018 in Blockchain by digger
• 26,740 points
1,212 views
0 votes
1 answer

In Excel, how to find a average from selected cells

If one has the dynamic array formula ...READ MORE

answered Oct 9, 2022 in Others by narikkadan
• 63,600 points
751 views
0 votes
1 answer

How to unmerge multiple cells and transpose each value into a new column in Pandas dataframe from excel file

Try this: df = pd.read_excel("Sample_File.xlsx", header=[0,1,2,3,4,5], index_col = ...READ MORE

answered Jan 8, 2023 in Others by narikkadan
• 63,600 points
2,528 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP