Data input pop up box

simonf

Board Regular
Joined
Jun 18, 2002
Messages
207
Hi all,

I have written a simple macro to insert a row between each of a preset range of rows.

Sub InsertRows()

For i = 1 To 5

ActiveCell.Offset(1, 0).Range("A1").Select
ActiveWindow.SelectedSheets.HPageBreaks.Add Before:=ActiveCell

Next i

End Sub

Is it possible to have a pop up input box for the user to input the number of rows to insert when the macro is run?

eg. Alt F8 and select InsertRows macro
Pop up box to input number of rows
Click "ok" and the macro continues to run to insert the rows.

Thanks in advance. :biggrin:
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
I'm not sure what you are trying to do. This code does not insert rows, it inserts page breaks.
 
Upvote 0
Does this work for you?

Code:
Sub InsertRows()
Dim i, j As Long
Do Until IsNumeric(i) And i <> ""
    i = InputBox("Enter number of page breaks to insert")
    If i = "" Then Exit Sub
    If i < 1 Or i > 1026 Then i = ""
Loop

For j = 1 To i
    ActiveCell.Offset(1, 0).Select
    ActiveWindow.SelectedSheets.HPageBreaks.Add Before:=ActiveCell
Next j

End Sub
 
Upvote 0
Wow, that's amazing! I never knew about this InputBox command. Thanks for all your help. :biggrin:
 
Upvote 0

Forum statistics

Threads
1,214,523
Messages
6,120,047
Members
448,940
Latest member
mdusw

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