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;

Sub InsertNumbers()

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
ActiveCell.Offset(1, 0).Activate
Next counter
Last: Exit Sub
End Sub

How to Insert Numbers Using Macros in Excel 1

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)

How to Insert Numbers Using Macros in Excel 2

Like this, now you can easily insert consecutive numbers by using macros.