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
 
Try
Code:
Sub ateebali2()
   Dim Ar As Areas
   Set Ar = Range("A5:A250").SpecialCells(xlVisible).Areas
   Ar(Ar.Count).Offset(1, 1).Resize(1, 15).ClearContents
   Ar(Ar.Count).EntireRow.Hidden = True
End Sub
 
Upvote 0

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Please do not ask members here to help you on another site (see rule#4)
If you are having problems with the code, then need to specify what those problems are.
 
Upvote 0
All right sir, see below codes;

This is to unhide rows between A5:A250

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

This is to hide rows between A250:A9 as well as it will clear content to next rows means A250 then A246 so on till A10

Sub deleterow()

Dim Ar As Areas
Set Ar = Range("A5:A250").SpecialCells(xlVisible).Areas
Ar(Ar.Count).Offset(1, 1).Resize(1, 15).ClearContents
Ar(Ar.Count).EntireRow.Hidden = True
End Sub



This is last code which I added to clear contents of selected rows and hide Row 9:250
Sub Clear_Me()
'Modified 12/29/2018 2:34:32 AM EST
Application.ScreenUpdating = False
Dim i As Long
For i = 6 To 250 Step 4
Cells(i, 2).Resize(, 15).ClearContents
Next
Range("B9:B250").Select
Range("B250").Activate
Selection.EntireRow.Hidden = True
Range("B6").Select


Application.ScreenUpdating = True
End Sub
 
Upvote 0
The first two codes are the ones I supplied & you said they worked, so what is your question?
 
Last edited:
Upvote 0
Yes sir but when I applied third code, now all rows are hidden, need code to unhide all
Also hide rows code should not work when we press button and only A5:A6 rows are displayed
If the code hide row A5:A6, then unhide row code is not working
 
Upvote 0
How about
Code:
Sub deleterow()
 
   Dim Ar As Areas
   Set Ar = Range("A5:A250").SpecialCells(xlVisible).Areas
   If Ar.Count = 1 Then Exit Sub
   Ar(Ar.Count).Offset(1, 1).Resize(1, 15).ClearContents
   Ar(Ar.Count).EntireRow.Hidden = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,184
Members
453,020
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