Running A Macro for Specific Rows Only

TJC86

New Member
Joined
Aug 27, 2014
Messages
17
Hi,

I'm sure this is really simple but I can't figure it out for the life of me. I have the following Macro:

Sub UnhideRow1()
Dim i As Long
If columns("A").SpecialCells(xlCellTypeVisible).Count = rows.Count Then Exit Sub
i = 1
Do Until rows(i).Hidden = True
i = i + 1
Loop
rows(i).Hidden = False
End Sub


It works okay, but I only want it to work for rows 50:77 as I have hidden rows after that which I don't want to unhide.

How can I limit the macro to run just for these rows. I've been all over Google and can't get it to work.

Thank you!!
 
Last edited:

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
I have hidden rows, and by clicking a button I want to be able to unhide the next hidden row, just 1 at a time, but for the macro not to unhide anything before row 50 or after row 77.

It works fine unhiding each row one at a time, but it carries on past row 77.
 
Upvote 0
I have hidden rows, and by clicking a button I want to be able to unhide the next hidden row, just 1 at a time, but for the macro not to unhide anything before row 50 or after row 77.

It works fine unhiding each row one at a time, but it carries on past row 77.
Question... could Row 49 ever be hidden?
 
Upvote 0
Sorry, I meant Unhide anything Between rows 49 and 77.

Apologies, long day!

Thanks for your help.
 
Upvote 0
Sorry, I meant Unhide anything Between rows 49 and 77.
Between is a tricky word... should Rows 49 and 77 be included or excluded along with Rows 50 to 76?

Whichever, I am interested in knowing if the row before the first row you want the ability to unhide could ever be hidden.
 
Last edited:
Upvote 0
Yes, row 48 could be hidden. Sorry if I'm not explaining well!

If rows 50:77 are hidden, then unhide at the click of the button one at a time, but if I click and it's row 90 that's hidden, don't unhide it!
 
Upvote 0
Yes, it can be hidden.
Okay, give this macro a try...
Code:
Sub ShowFirstHiddenRow()
  If Rows(50).Hidden Then
    Rows(50).Hidden = False
  Else
    On Error Resume Next
    With Range("A49:A77").SpecialCells(xlVisible)
      .Areas(1)(.Areas(1).Count).Offset(1).EntireRow.Hidden = False
    End With
    On Error GoTo 0
  End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,101
Messages
6,170,116
Members
452,302
Latest member
TaMere

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