I am trying to add borders to a certain range in excel. Because I eventually want to use this code in a For loop, I want to define the Range using Cells().
This code does not work:
With ThisWorkbook.Worksheets("Data").Range(Cells(1, 1), Cells(1, 3)).Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 1
End With
But this code (that refers to the same exact range) does not:
With ThisWorkbook.Worksheets("Data").Range("A1:C1").Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 1
End With
What is going on here?
The error I get is
"Run-time error '1004': Application-defined or object-defined error".