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

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
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,223,214
Messages
6,170,772
Members
452,353
Latest member
strainu

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