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

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
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,223,893
Messages
6,175,246
Members
452,623
Latest member
cliftonhandyman

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