VBA Code - Refer to Range and Rows

tlc53

Active Member
Joined
Jul 26, 2018
Messages
379
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!
 

Some videos you may like

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
36,675
Office Version
  1. 2010
Platform
  1. Windows
Try it this way...

Range("208:604,619:619,629:629").EntireRow.Hidden = True
 

tlc53

Active Member
Joined
Jul 26, 2018
Messages
379
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.
 

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
36,675
Office Version
  1. 2010
Platform
  1. Windows
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:

tlc53

Active Member
Joined
Jul 26, 2018
Messages
379

ADVERTISEMENT

Whoops! Sorry :oops:
Thanks for that! Works perfectly! :)
 

tlc53

Active Member
Joined
Jul 26, 2018
Messages
379
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.
 

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
36,675
Office Version
  1. 2010
Platform
  1. Windows
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,122,233
Messages
5,594,963
Members
413,954
Latest member
mrsandy

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
Top