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

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
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,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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