Looping through various ranges

MikeWip

New Member
Joined
Feb 13, 2017
Messages
45
Bonjour guys,

hope you can help me with the below?

I have this code below working for one given range (e.g. For Each A In Range("AE4:AE500") but as soon as I try adding more ranges to loop through, it gets stuck.
any idea why?

the code needs to check all ranges and only if all ranges are not blank then it should hide the relevant row.


Sub Hide_Rows_Containing_Value()

Application.ScreenUpdating = False

Dim A As Range


For Each A In Range("AE4:AE500" & "AF4:AF500" & "AG4:AG500" & "AH4:AH500" & "AI4:AI500").Cells
If A.Value <> "" Then
A.EntireRow.Hidden = True
End If

Next A


Application.ScreenUpdating = True


End Sub


cheers for your help,
Mike
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
How about
Code:
Sub MikeWip()
   Dim Cl As Range
   Application.ScreenUpdating = False
   For Each Cl In Range("AE4:AE500")
      Cl.EntireRow.Hidden = Application.CountA(Cl.Resize(, 5)) = 5
   Next Cl
End Sub
 
Upvote 0
You're a genius!!!! Thank you so much. I have gone nuts for hours and you fixed it in less than 5 mins. thanks buddy!!!
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,213,521
Messages
6,114,109
Members
448,548
Latest member
harryls

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