VBA Code Error - Reveal next line in multiple areas

tlc53

Active Member
Joined
Jul 26, 2018
Messages
399
Hi there,

I use the below code to automatically reveal a row as the user enters details. It's been working fine but in this case, there are many ranges to take into account and when I tried to put it all under one, it came back with a syntax error (it's too long). Therefore, I am trying to break it into two, as below. However, I'm not quite sure how/if it can be done.
Can someone help me fix this VBA code please?
Thank you!


Code:
Private Sub Worksheet_Change(ByVal Target As Range)


Dim Rng As Range
Set Rng = Intersect(Target, [B21:B29,I21:I29,B47:B55,I47:I55,B73:B81,I73:I81,B99:B107,I99:I107,B125:B133,I125:I133,B157:B161,I157:I161,B175:B184,I175:I184,B191:B199,I191:I199,B221:B225,I221:I225,B239:B248,I239:I248])
If Not Rng Is Nothing Then Rng(2, 1).EntireRow.Hidden = False


End If


Dim Rng As Range
Set Rng = Intersect(Target, [B225:B263,I225:I263,B285:B289,I285:I289,B303:B312,I303:I312,B319:B327,I319:I327,B349:B353,I349:I353,B367:B376,I367:I376,B383:B391,I383:I391,B413:B417,I413:I417,B431:B440,I431:I440,B447:B455,I447:I455])
If Not Rng Is Nothing Then Rng(2, 1).EntireRow.Hidden = False


End Sub
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
It might go on one line with this :
Code:
Dim Rng As Range
Set Rng = Intersect(Target, Intersect([B:B,I:I], [21:29,47:55,73:81,[COLOR=#ff0000]ETC][/COLOR])) [COLOR=#ff0000]'Replace ETC with the rest of the row refs[/COLOR]
If Not Rng Is Nothing Then Rng(2, 1).EntireRow.Hidden = False
 
Upvote 0
Thanks footoo. It was a good idea. I thought it would work but unfortunately not. It's coming back with Run time error 424, object required.
 
Upvote 0
Try
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   Dim Rng As Range
   Set Rng = Intersect(Target, [B21:B29,I21:I29,B47:B55,I47:I55,B73:B81,I73:I81,B99:B107,I99:I107,B125:B133,I125:I133,B157:B161,I157:I161,B175:B184,I175:I184,B191:B199,I191:I199,B221:B225,I221:I225,B239:B248,I239:I248])
   If Not Rng Is Nothing Then Rng(2, 1).EntireRow.Hidden = False
   Set Rng = Intersect(Target, [B225:B263,I225:I263,B285:B289,I285:I289,B303:B312,I303:I312,B319:B327,I319:I327,B349:B353,I349:I353,B367:B376,I367:I376,B383:B391,I383:I391,B413:B417,I413:I417,B431:B440,I431:I440,B447:B455,I447:I455])
   If Not Rng Is Nothing Then Rng(2, 1).EntireRow.Hidden = False
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,642
Messages
6,120,698
Members
448,979
Latest member
DET4492

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