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
 
How about
Code:
Sub ateebali()
   Dim Ar As Areas
   Set Ar = Range("A5:A250").SpecialCells(xlVisible).Areas
   Ar(Ar.Count).EntireRow.Hidden = True
End Sub
 
Upvote 0

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
You're welcome & thanks for the feedback
 
Upvote 0
Dear Air,
One more query, like when they are hiding rows, it should also clear contents from column B:P of hidden rows
 
Upvote 0
Like
Code:
Sub ateebali2()
   Dim Ar As Areas
   Set Ar = Range("A5:A250").SpecialCells(xlVisible).Areas
   Ar(Ar.Count).Offset(, 1).Resize(, 15).ClearContents
   Ar(Ar.Count).EntireRow.Hidden = True
End Sub
 
Upvote 0
Dear Sir
This code also clearing content of ROW# 13 which is header and which I don't want to clear content
What I want;
It hide Row# 13 & 14 but clear content only row# 14 (column: B:P)
Next Click, It should hide Row# 9 & 10 but clear content only Row: 10
 
Upvote 0
Dear Si, please respond back, thanks a lot in advance

This forum has volunteers only, they do what they can when they can, they are not here continuously, and are unpaid, and they can be anywhere in any timezone
 
Upvote 0

Forum statistics

Threads
1,214,918
Messages
6,122,241
Members
449,075
Latest member
staticfluids

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