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

Aim of achievement: To get rid of the borders, if they are in the cells of the 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

Please, help..!

I am new to Vb.net!

+5
source share
4 answers
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

Deletes borders around cells and between cells (through xlInsideHorizontaland xlInsideVertical). If you expect diagonal borders, turn on xlDiagonalDownand xlDiagonalUp.

Well, the code above 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

EDIT:

MSDN , :

range.Borders.LineStyle = Excel.XlLineStyle.xlLineStyleNone
+17

( "A2: K100" ). Borders.LineStyle = xlNone

+2

Check the NamedRange.BorderAround Method .

Dim range As Excel.Range = sheet.Range("A2:K100")
range.BorderAround(Excel.XlLineStyle.xlLineStyleNone, Excel.XlBorderWeight.xlThin, Microsoft.Office.Interop.Excel.XlColorIndex.xlColorIndexAutomatic, missing)

greetings and good luck!

+1
source

why are all the answers so confusing?

for all sheet use ...

With .Cells
       .Borders.LineStyle = xlLineStyleNone
End With

for the range that is just being replaced. Matching characters

0
source

All Articles