Borders Macro runtime error Need Help

danjw_98

Active Member
Joined
Oct 25, 2003
Messages
354
I am using the below macro to create borders on multiple sheets but it gives me a runtime error 1004 "unable to set the weight property of the border class". I thought if i removed them first it would fix the problem but it didn't. Any help would be appreciated...thanks..


Sub FormatBorders()
Application.ScreenUpdating = False
'On Error Resume Next
Dim wrkSheet As Worksheet

For Each wrkSheet In Sheets(Array("Sheet1", "sheet2", "sheet3"))
With wrkSheet

lastrow = .Range("c65536").End(xlUp).Row
For x = 2 To lastrow

Set rng = .Range("A" & x & ":r" & x)

With rng
.Borders.LineStyle = xlNone
.Borders(xlEdgeTop).Weight = xlThin
.Borders(xlEdgeBottom).Weight = xlThin
.Borders(xlEdgeLeft).Weight = xlThin
.Borders(xlEdgeRight).Weight = xlThin
.Borders(xlInsideVertical).Weight = xlThin
End With


Next x
End With
Next wrkSheet

Application.ScreenUpdating = True

End Sub
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
i have gone thru and x'd out each one and still get the error except the top line runs. thanks for looking at this...


.Borders.LineStyle = xlNone
'.Borders(xlEdgeTop).Weight = xlThin
'.Borders(xlEdgeBottom).Weight = xlThin
'.Borders(xlEdgeLeft).Weight = xlThin
'.Borders(xlEdgeRight).Weight = xlThin
'.Borders(xlInsideVertical).Weight = xlThin
 
Upvote 0
I have no problem with that scenario either. How may cells are you formatting on each worksheet? The worksheets aren't protected are they?
 
Upvote 0
there is no protection on the workbook or sheets and the number of rows would vary (adding info).
 
Upvote 0

Forum statistics

Threads
1,224,607
Messages
6,179,871
Members
452,948
Latest member
UsmanAli786

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top