VBA Code - Refer to Range and Rows

tlc53

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

Can I refer to a range and row reference in one line of code?

Eg.

Code:
Case 0      Range("208:604").Rows("619, 629").EntireRow.Hidden = True

So I would like to hide range "208:604" and single rows, 619 and 629. The above doesn't work.

Thank you!
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Try it this way...

Range("208:604,619:619,629:629").EntireRow.Hidden = True
 
Upvote 0
Hi. Thanks.

The problem is I have to refer to 80 singular rows along with multiple ranges, so if I mark my single rows as ranges, it gets too long and won't accept the code.
 
Upvote 0
Hi. Thanks.

The problem is I have to refer to 80 singular rows along with multiple ranges, so if I mark my single rows as ranges, it gets too long and won't accept the code.
Hmm, I don't remember you telling us that in your original message. :LOL:

Okay, in that case, you will need to run a loop. Put your row ranges into a space delimited text string as shown.
Code:
Dim V As Variant

For Each V In Split("208:604 619 629")
  Rows(V).Hidden = True
Next
 
Last edited:
Upvote 0
Actually, it worked fine on the first Case but once I started copying the code for each Case, I started to run into problems.

I have decided to attack it from another angle.

How do I list multiple singular rows in this line of code? Is it possible?

Code:
    Case "Please Select"
        Rows("619,629,630,640").EntireRow.Hidden = True

The above doesn't work.
 
Upvote 0
Actually, it worked fine on the first Case but once I started copying the code for each Case, I started to run into problems.

I have decided to attack it from another angle.

How do I list multiple singular rows in this line of code? Is it possible?

Code:
    Case "Please Select"
        Rows("619,629,630[B][COLOR="#FF0000"]:630[/COLOR][/B],640[B][COLOR="#FF0000"]:640[/COLOR][/B]").EntireRow.Hidden = True

The above doesn't work.
You have to supply a "complete" range (row colon row) even for a single range (just put a colon and repeat the single row's number)... just add what I show in red above.
 
Upvote 0

Forum statistics

Threads
1,214,827
Messages
6,121,812
Members
449,048
Latest member
greyangel23

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