I am trying to make a small VBA script that looks at sheet names and if a sheet matches the criteria, sets a range.
I want it to then look in that range for an empty cell. If it finds an empty cell, I want it to hide the cell.
After finishing the range it then looks for the next suitable sheet in the workbook. It does this until no more sheets are available.
The code is not looking for the empty cells. What am I doing wrong?
I wrote this for just a single sheet and used to actuate it from a button and it worked fine. I think when I have a nested if statement, I am doing something wrong.
I want it to then look in that range for an empty cell. If it finds an empty cell, I want it to hide the cell.
After finishing the range it then looks for the next suitable sheet in the workbook. It does this until no more sheets are available.
VBA Code:
Sub HideUnusedRowsFloorRoof()
Dim cel As Range, rng As Range, ws As Worksheet
For Each ws In ActiveWorkbook.Sheets
If ws.Name Like "*Floor" Or ws.Name Like "*Roof" Then
Set rng = Range("M5:M200")
For Each cel In rng
If cel.Value = "" Then
cel.EntireRow.Hidden = True
End If
Next cel
End If
Next ws
End Sub
The code is not looking for the empty cells. What am I doing wrong?
I wrote this for just a single sheet and used to actuate it from a button and it worked fine. I think when I have a nested if statement, I am doing something wrong.