Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Excel VBA Macro to hide/unhide every 3rd, 4th & 5th row

Posted on 2009-04-07
6
Medium Priority
?
1,022 Views
Last Modified: 2012-05-06
Greetings; I need an Excel VBA Macro to hide/unhide every 3rd, 4th & 5th row on a particular workbook. I found a macro that hides every 3rd and 4th row but I haven't been able to figure out how to modify it to include the 5th row.

Thanks in advance for your consideration.
Hides every 3rd and 4th row:
 
Sub hiderows()
For i = Cells(Rows.Count, "a").End(xlUp).Row - 1 To 2 Step -3
Rows(i).Resize(2).Hidden = True
Next i
End Sub

Open in new window

0
Comment
Question by:dartanion_jm
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 85

Assisted Solution

by:Rory Archibald
Rory Archibald earned 2000 total points
ID: 24087415
Try this:
 

Sub hiderows()
Dim i
For i = Cells(Rows.Count, "a").End(xlUp).Row - 1 To 3 Step -5
Rows(i).Resize(3).Hidden = True
Next i
End Sub

Open in new window

0
 

Author Comment

by:dartanion_jm
ID: 24094316
Thanks for the prompt response Rorya.

Unfortunately the script provided unhid the 1st 5 rows; then hid the next 2 rows; unhide the next row then hid the next 3 rows. Still can't figure this script out.  

The original script provided is close...Unhide rows 1 and 2; hide rows 3 and 4.

Just need it to unhide rows 1 and 2; hide rows 3, 4 and 5; unhide row 6; hide rows 7, 8 & 9; unhide row 10; hide rows 11, 12 & 13...and continue on.

Any assistance you can provide is greatly appreciated. Thanks for your efforts.
0
 
LVL 85

Assisted Solution

by:Rory Archibald
Rory Archibald earned 2000 total points
ID: 24094414
That code doesn't unhide any rows so I don't get what you are seeing. Do you need the code to specifically unhide rows 1&2, 6&7 etc?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:dartanion_jm
ID: 24097364
Greetings Rorya; Sorry for the confusing  (am) explanation.

What I'm looking for (after rows 1 and 2 are left unhidden)  is for rows 3,4, & 5 hidden; then leave row 6 unhidden; then hide rows 7, 8 & 9 and continue on for the rest spreadsheet.

Unhidden
Unhidden
Hidden
Hidden
Hidden
Unhidden
Hidden
Hidden
Hidden
Unhidden

Thanks again.
0
 
LVL 85

Accepted Solution

by:
Rory Archibald earned 2000 total points
ID: 24099031
So not what you asked for originally then? ;)
Try this:
 

Sub hiderows()
Dim i as long, lngLastRow as long
lngLastRow = Cells(Rows.Count, "a").End(xlUp).Row 
For i = 3 to lngLastRow Step 4
Rows(i).Resize(3).Hidden = True
Next i
End Sub

Open in new window

0
 

Author Closing Comment

by:dartanion_jm
ID: 31567508
Matrix (1999) - Morpheus: "You are the ONE, Rorya!"

It works perfectly. Thank You for the prompt responses and your patience.
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
This article describes a serious pitfall that can happen when deleting shapes using VBA.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question