VBA Code - Refer to Range and Rows

tlc53

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

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
35,510
Office Version
2010
Platform
Windows
Try it this way...

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

tlc53

Active Member
Joined
Jul 26, 2018
Messages
334
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
35,510
Office Version
2010
Platform
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
334
Whoops! Sorry :oops:
Thanks for that! Works perfectly! :)
 

tlc53

Active Member
Joined
Jul 26, 2018
Messages
334
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
35,510
Office Version
2010
Platform
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.
 

Forum statistics

Threads
1,082,371
Messages
5,365,055
Members
400,819
Latest member
Gossow

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top