Hi, I really hope someone can help me with this query. I'm a novice when it comes to VBA so be gentle.
I want to create a macro that will loop through ALL worksheets (the names of these are variable and not known in advance) EXCEPT one which is fixed (call it "FixedSheet"). I want the macro to delete all hidden rows and columns on all these sheets regardless of whether they have data. If they're hidden I want them deleted. Simple.
The code below worked once, but after saving and re-executing it no longer does, something about Select of Object Worksheet failed (runtime 1004). Granted this code does not exclude a worksheet but you get the gist.
Help very much appreciated.
Dim mysheet As Worksheet
For Each mysheet In Worksheets
mysheet.Select
For lp = 256 To 1 Step -1 'loop through all columns
If Columns(lp).EntireColumn.Hidden = True Then Columns(lp).EntireColumn.Delete Else
Next
For lp = 65536 To 1 Step -1 'loop through all rows
If Rows(lp).EntireRow.Hidden = True Then Rows(lp).EntireRow.Delete Else
Next
Next
End Sub
I want to create a macro that will loop through ALL worksheets (the names of these are variable and not known in advance) EXCEPT one which is fixed (call it "FixedSheet"). I want the macro to delete all hidden rows and columns on all these sheets regardless of whether they have data. If they're hidden I want them deleted. Simple.
The code below worked once, but after saving and re-executing it no longer does, something about Select of Object Worksheet failed (runtime 1004). Granted this code does not exclude a worksheet but you get the gist.
Help very much appreciated.
Dim mysheet As Worksheet
For Each mysheet In Worksheets
mysheet.Select
For lp = 256 To 1 Step -1 'loop through all columns
If Columns(lp).EntireColumn.Hidden = True Then Columns(lp).EntireColumn.Delete Else
Next
For lp = 65536 To 1 Step -1 'loop through all rows
If Rows(lp).EntireRow.Hidden = True Then Rows(lp).EntireRow.Delete Else
Next
Next
End Sub