Vb Code Unhide rows

ateebali

Board Regular
Joined
Dec 13, 2018
Messages
108
Dear Sir,
I am using following code to add rows from A5:A498
It add rows in a way like, It unhide Row: A9:10, then A13:14
A11:A12 keep hidden, same way it goes all the way to A498

Code:
Sub addrow()   Dim Ar As Areas
   Set Ar = Range("A5:A498").SpecialCells(xlVisible).Areas
   Ar(Ar.Count).Offset(4).Resize(2).EntireRow.Hidden = False
End Sub

Now I need a code when I play it, it should unhide all the rows from A5:A498 in same pattern like;
A5:A6 = Unhide
A9:10 = Unhide
A13:14 = Unhide
All the way to A498 should be unhide in same pattern and in between rows should be keep hidden
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Code:
Dim rng As Range, r%
[A5:A498].EntireRow.Hidden = True
Set rng = [A5:A6]
For r = 9 To 498 Step 4
    Set rng = Union(rng, Cells(r, 1).Resize(2))
Next
rng.EntireRow.Hidden = False
 
Last edited:
Upvote 0
Try this:
Code:
Sub addrow()   Dim Ar As Areas
   Set Ar = Range("A5")
do until ar.row >498
   Ar.Resize(2).EntireRow.Hidden = False
   Ar.offset(2).Resize(2).EntireRow.Hidden = true
  set ar=ar.offset(4)
loop
Range("A499:A500").EntireRow.Hidden = False
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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