Reputation: 133
I am running a macro that sets the format of a group of cells.
Public LastRow as Integer
Sub Formatting()
LastRow = 20
With ThisWorkbook.Sheets("Sheet1").Range("A15:" & "AA" & LastRow)
.Borders.Weight = xlThin
End With
End Sub
When I run the macro the first time it works but on the second time I receive the following error Run-time error '1004': Unable to set the Weight property of the Borders class.
Also I am unable to manually change the borders of the effected cells now. I'm not sure what is happening. I am running excel 2010
Thanks in advance,
Upvotes: 0
Views: 2647
Reputation: 149297
Few Things
Function
for this. Use a Sub
. You use a Function
when you want to return somethingLastRow
anywhere.Try this
Sub Formatting()
Dim LastRow As Long
LastRow = 20
'~~> Change Sheet1 to the relevant sheetname or use Code Name
With ThisWorkbook.Sheets("Sheet1").Range("A15:" & "AA" & LastRow)
.Borders.Weight = xlThin
End With
End Sub
Upvotes: 1