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

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

Scott Huish

MrExcel MVP
Joined
Mar 17, 2004
Messages
19,958
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
I'm not sure what you are trying to do. This code does not insert rows, it inserts page breaks.
 

simonf

Board Regular
Joined
Jun 18, 2002
Messages
207
My bad. You are correct. I am inserting page breaks rather than rows. :oops:
 

Scott Huish

MrExcel MVP
Joined
Mar 17, 2004
Messages
19,958
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
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
 

simonf

Board Regular
Joined
Jun 18, 2002
Messages
207
Wow, that's amazing! I never knew about this InputBox command. Thanks for all your help. :biggrin:
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,168,128
Messages
5,857,531
Members
431,884
Latest member
Gcmoore63

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
Top