VB Code to hide and unhide rows

ateebali

Board Regular
Joined
Dec 13, 2018
Messages
108
Dear Sir
Using following code;

Sub Macro1()
'
' Macro1 Macro
'


'
Range("A7:A8").Select
Selection.EntireRow.Hidden = False


End Sub

It is linked with button, when I click it, its Unhide the rows A7:A8
I need to write the code then when we click again, it should hide A10:A11
then when click again it should hide A13:A14
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Give this code a try...
Code:
Sub Macro2()
  Rows("7:8").Hidden = Not Rows("7:8").Hidden
End Sub
 
Upvote 0
could something be hidden on sheet, so when the user clicks the button to swap, the number is updated for the next triple ?
 
Upvote 0
Yes wanted to do it for next triple
When click once, row A7:A8 unhidden
then again click same button, so it will unhide row A9:A10
again A12:A13, it will go like wise to bottom till A250, it will be ending
 
Upvote 0
Your requirements are changing, in post#1 you said
A7:A8
A10:A11
A13:A14
in post#4 you said
A7:A8
A9:A10
A12:A13

Which is correct?
Also are all rows 7:250 hidden to begin with?
 
Upvote 0
Dear Sir,
I want to understand vb code with formula, as requirement can be changed if I add more rows, still I am finalizing the format sheet, currently requirement is as;
All rows are hidden except A1:A6 (complete row)
I have made a button (Form Control) need to link it with vb code, when I click it first time, it will show row# A9:A10 and keep hidden Row A7:A8
When Click sever time, it will unhide next rows for example, A13:A14 (A11:A12 will keep hidden)
Next press will unhide A17:A18 (A15:A16 will keep hidden)
Similarly It goes till A250 this is where I want to end my data at max.
Formula will remain same like 02 rows jump or 03 rows jump or 01 row jump over to the last
 
Last edited:
Upvote 0
How about
Code:
Sub ateebali()
   Dim Ar As Areas
   Set Ar = Range("A5:A250").SpecialCells(xlVisible).Areas
   Ar(Ar.Count).Offset(4).Resize(2).EntireRow.Hidden = False
End Sub
 
Upvote 0
Alright, I am confused. When you first start, is range 7:250 hidden? If yes, then the first time you run the macro, you want rows 7:8 visible, correct? What happens next is where I'm confused. The next time you run the macro, you want rows 10:11 made visible, but what about rows 7:8... do they stay visible also or are they to become hidden?
 
Upvote 0
This is perfect code, thanks a lot
Please also advice code for reverse, this time it will hide the rows from bottom first.
For example if ROW 21:22 is visible, it will hide 21:22 fir first click, next click, it will hide 17:18, next it will hide 13:14
It will also through row 250
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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