Hide rows for a specific worksheet

SilKitty

New Member
Joined
Apr 18, 2013
Messages
3
Hello everyone,
I would appreciate some help with this macro. I have two sheets. Sheet 1 is where I want the macro button to be and Sheet 2 is where I want it to do its thing. I want to hide all rows between 108 to 197 that are empty at column A. I have the following macro which works, but does its thing on Sheet 1 and not Sheet 2! Please help! Thank you!

Sub HideBlankRows()
Application.ScreenUpdating = False
Dim ws As Worksheet
Dim i As Integer
For Each ws In ThisWorkbook.Worksheets

For i = 108 To 197
If ws.Name = "Sheet 2" And Cells(i, "A") = "" Then
Rows(i).EntireRow.Hidden = True
End If
Next i
Next ws
Application.ScreenUpdating = True
End Sub
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Try

Code:
Sub HideBlankRows()
Dim i As Long
Application.ScreenUpdating = False
With Sheets("Sheet2")
    For i = 108 To 197
        .Rows(i).Hidden = .Range("A" & i).Value = ""
    Next i
End With
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Like that would be better

Sub HideBlankRows()

Application.ScreenUpdating = False
Dim ws As Worksheet
Dim i As Integer, k as integer
For Each ws In ThisWorkbook.Worksheets

for k=1 to sheets.count

if sheets(k).name="Sheet2" then

For i = 108 To 197
If sheets(k).Cells(i, 1) = "" Then
sheets(k).Rows(i).EntireRow.Hidden = True
End If
Next i

end if

next k

Application.ScreenUpdating = True
End Sub
 
Upvote 0
Thanks so much for your help! Works great. My next question is about this section of the first macro :

...
With Sheets("Sheet2") For i = 108 To 197 .Rows(i).Hidden = .Range("A" & i).Value = ""
...

How can I modify the last line so that the macro would check that BOTH Ai AND Ni are blank to hide the rows under?
My worksheet is 2 columns and they are both dynamic lists and move up and down, so I want to hide the rows under the longest list.

Thanks so much!
</pre> Sil
 
Upvote 0
Try

Code:
.Rows(i).Hidden = .Range("A" & i).Value = "" And .Range("N" & i).Value = ""
 
Upvote 0

Forum statistics

Threads
1,214,585
Messages
6,120,391
Members
448,957
Latest member
Hat4Life

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