Reputation: 23
I'd like to run a macro on every sheet except sheet1 and sheet2.
dim rs as worksheet
for each rs in sheets
if rs.name = "Sheet1" or "Sheet2" then
next rs
else rs.name =rs.range("
I get the error
next without for
How can I use next the for loop and the if statement?
Dim rs As Worksheet
For Each rs In Sheets
If rs.Name = "sheet1" Or "sheet2" Then
Next ws
Else: rs.Name = rs.Range("N2") 'rename sheet base on vendor name field
End If
Next rs
Upvotes: 1
Views: 24590
Reputation: 33682
Small mixup, try :
Dim rs As Worksheet
For Each rs In ThisWorkbook.Worksheets
If rs.Name <> "Sheet1" And rs.Name <> "Sheet2" Then
rs.Name = rs.Range("N2").Value 'rename sheet base on vendor name field
End If
Next rs
End Sub
Upvotes: 8