Newbie Help - VBA to hide rows based on user input

roboto

New Member
Joined
Jan 30, 2012
Messages
4
I am a complete newbie when it comes to writing macros, but I was wondering if someone would be able to help me?

I want to click on a button (I know how to assign a macro to a button) and have a macro run that asks me which row numbers to hide and then pop up a print dialog.

Is this doable? I would appreciate any help any one could give me!
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Try

Code:
Sub atest()
Dim x
Dim s As String, i As Long
s = InputBox("Enter row numbers to hide separated by ,")
x = Split(s, ",")
For i = LBound(x) To UBound(x)
    Rows(x(i)).Hidden = True
Next i
End Sub
 
Upvote 0
Thank you for your help! I have one question though, is there a way to make it apply to a range? For example, if I want to hide rows 60-100 is there a way that I don't have to type in each row separated by a comma?
 
Upvote 0
Try

Code:
Sub atest()
Dim x
Dim s As String, i As Long, j As Long, k As Long
s = InputBox("Enter row numbers to hide separated by -")
x = Split(s, "-")
i = x(LBound(x))
j = x(UBound(x))
For k = i To j
    Rows(k).Hidden = True
Next k
End Sub
 
Upvote 0
Amazing! Thank you so much. You have made my life so much easier!

I take it there is no way for it to pop up a print dialog automatically then?
 
Upvote 0
Try

Code:
Sub atest()
Dim x
Dim s As String, i As Long, j As Long, k As Long
s = InputBox("Enter row numbers to hide separated by -")
x = Split(s, "-")
i = x(LBound(x))
j = x(UBound(x))
For k = i To j
    Rows(k).Hidden = True
Next k
Application.Dialogs(xlDialogPrint).Show
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,394
Messages
6,119,262
Members
448,880
Latest member
aveternik

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