Insert Numbers Using Macros in Excel
If you ever need to insert consecutive numbers in excel then use the macros it will be helpful for you. In this tutorial, we will show the way of insert numbers by using macros in excel.
How it works: firstly it asks for a max number and then it generates numbers from 1 to the max number you need.
Before following the procedure of this tutorial make sure you have enabled the Excel’s Developer Tab.
Previously In macros: How to Remove Text Wrap Using Macros in Excel
STEP 1: GO TO DEVELOPER> CODE> VISUAL BASIC> COPY/PASTE THE CODE BELOW > CLOSE THE WINDOW
Copy The Code Below;
Dim maxNumber As Integer
Dim counter As Integer
On Error GoTo Last
maxNumber = InputBox(“Enter the Max Value”, “Generate 1 to n”)
‘Generate all the numbers
For counter = 1 To maxNumber
ActiveCell.Value = counter
‘Move one cell below
Last: Exit Sub
STEP2. In this step select that cell where you need to insert number on and follow this:
Go to Developer > Code > Macros > Run (Enter The Value you want to insert afterwards)
Like this, now you can easily insert consecutive numbers by using macros.