PDA

View Full Version : Loop through every worksheet except



Shazam
11-30-2006, 11:15 AM
Hi everyone,

I would like this code below to loop through every worksheet in the workbook and delete the last active row in column C, But ignore the active worksheet and "Individual Report" and Comparison Chart" worksheets.

I tried the code below but no luck. Can we modify it to make it work?


Sub Test()

Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets

If ws.Name <> ActiveSheet.Name And ws.Name <> "Individual Report" And ws.Name <> "Comparison Chart" Then

Rows(Range("C65536").End(xlUp).Row).Delete ' Delete last active row

With ws

End With
End If
Next

Next ws
End Sub

Norie
11-30-2006, 11:58 AM
The problem with the code is that you aren't referencing ws within the If End If.


Sub Test()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
If ws.Name <> ActiveSheet.Name And ws.Name <> "Individual Report" And ws.Name <> "Comparison Chart" Then
ws.Range("C65536").End(xlUp).EntireRow.Delete ' Delete last active row
End If
Next ws
End Sub

Shazam
11-30-2006, 12:29 PM
The problem with the code is that you aren't referencing ws within the If End If.


Sub Test()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
If ws.Name <> ActiveSheet.Name And ws.Name <> "Individual Report" And ws.Name <> "Comparison Chart" Then
ws.Range("C65536").End(xlUp).EntireRow.Delete ' Delete last active row
End If
Next ws
End Sub


Thank You Norie its perfect!!