I am new to writing VBA scripts and I am having problems getting my scripts to run. My code is:
Sub Cellborder()
'Formats all cells, below the row with column headings, that have data with cell borders
Dim nLastRow As Long
Dim nLastColumn As Long
Dim nLastCell As Long
nLastRow = ActiveSheet.UsedRange.Rows.Count
nLastCol = ActiveSheet.UsedRange.Columns.Count
nLastCell = ActiveSheet.Cells(nLastRow, nLastCol)
ActiveSheet.Range("A7").SpecialCells(xlCellTypeLastCell).Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
End Sub
When ever I try to run it, it comes up with a error 400. What could the problem be?
Bookmarks