How to Insert Numbers Using Macros (VBA) in Excel Office 365?
Tags: insertnumbersusingma, vbamacros
Published: 2020-09-29 04:32:30

---
title: How to Insert Numbers Using Macros (VBA) in Excel Office 365?
published: true
date: 2020-09-28 12:26:13 UTC
tags: InsertNumbersUsingMa,VBAMacros
canonical_url: https://geekexcel.com/how-to-insert-numbers-using-macros-vba-in-excel-office-365/
---

## Insert Numbers Using Macros in Excel:

In this article, you will learn the steps to **Insert Numbers Using Macros in Excel Office 365** with an example. Let’s jump into this article!! Get an official version of **MS Excel** from the following link: [https://www.microsoft.com/en-in/microsoft-365/excel](https://www.microsoft.com/en-in/microsoft-365/excel)
## **Steps to Insert Numbers Using Macros:**

- You need to go to the **Developer Tab, choose** the **Visual Basic** option under the **Code** section.

![Select the Visual Basic option](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2020/09/Select-the-Visual-Basic-option.png)<figcaption id="caption-attachment-14695">Select the Visual Basic option</figcaption>

- You have to activate the sheet where you want to insert the numbers.
- Now, enter the below code.

VBA code for inserting numbers in Excel

Sub InsertNumbers()

Dim maxNumber As Integer

Dim counter As Integer

On Error GoTo Last

maxNumber = InputBox(“Enter the Max Value”, “Generate 1 to n”)

‘It will generate all numbers

For counter = 1 To maxNumber

ActiveCell.Value = counter

‘To Move one cell below

ActiveCell.Offset(1, 0).Activate

Next counter

Last: Exit Sub

End Sub

- You need to **save the code** by selecting it. Then close the window.

![Enter the source code](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2020/09/Enter-the-source-code.png)<figcaption id="caption-attachment-14696">Enter the source code</figcaption>

- Now, you need to **select any cell** where you want to insert the numbers.
- Then, on the **Developer Tab, select** the **Macros** option in the **Code** section.

![Choose Macros option](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2020/09/Choose-Macros-option-1.png)<figcaption id="caption-attachment-14697">Choose Macros option</figcaption>

- You have to make sure that your macro is selected and **click** the **Run** button.

![Macro dialog box](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2020/09/Macro-dialog-box-2.png)<figcaption id="caption-attachment-14698">Macro dialog box</figcaption>

- It will open the **Generate**  **1 to n dialog box** , you have to give the input of how many numbers to be inserted.
- You have to **click** the **OK** button to get the result.

![Generate 1 to n dialog box](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2020/09/Generate-1-to-n-dialog-box.png)<figcaption id="caption-attachment-14699">Generate 1 to n dialog box</figcaption>

- After clicking the OK button, you can get the output as shown in the below image.

![Result](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2020/09/Result-9.png)<figcaption id="caption-attachment-14700">Result</figcaption>

## **Conclusion:**

In this article, you can understand the steps to **Insert Numbers Using Macros in Excel Office 365** with an example. Leave your **feedback** in the comment section. Thanks for visiting **[Geek Excel.](https://geekexcel.com/)** Keep Learning!!