Excel macro to sequential numbering base on initial and final number

ColdSpirit

New Member
Joined
Sep 30, 2022
Messages
18
Office Version
  1. 2010
Platform
  1. Windows
Hello all!

I am new to programming in general, and I know very little of Excel VBA / macros.

I need help inserting a sequential number from A6 to a dynamic number based on a previous number.

Example: I have an initial number(B1) and a final number(B2), and finally, the amount between the initial number and the final number, which I call the total (including)(B3).

B2-B1=B3

and I want to insert a sequential number on A6 to the final number with increments of +1 until It reaches the final number.

A6 should have the initial number too.

1666479452695.png


At the moment the code I have is this:
VBA Code:
Private Sub CommandButton1_Click()
Dim ni As Range 'determinar o numero inicial
Dim nf As Range 'determinar o numero final
Dim ws As Worksheet 'determinar o valor "ws" como worksheet

Set ws = ThisWorkbook.Sheets("047") 'associar "ws" à folha "047"
Set ni = Range("B1") 'associar ni = Célula J1
Set nf = Range("B2") 'associar fi = Célula J2
Set Total = Range("B3") 'associar total = Célula J3

Columns(1).ClearContents 'limpar a coluna A(1)

ni = _
InputBox(Prompt:="Inserir Numero Inicial") 'ni -inserção da numeração inicial (+ criação da inputbox)

nf = _
InputBox(Prompt:="Inserir Numero Final") 'fi -inserção da numeração final (+ criação da inputbox)

    MsgBox "Numeração AWB inserida com sucesso" 'mensagem após inserção de numeração da awb

End Sub

Many thanks in advance.
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Hi ColdSpirit,

Here's one way based on mirabeau's nifty solution from here that I was part of some years ago:

VBA Code:
Option Explicit
Sub Macro1()

    'Based on mirabeau's solution from https://www.mrexcel.com/board/threads/looping-x-number.579026

    Dim ws As Worksheet
   
    Set ws = ThisWorkbook.Sheets("047")
   
    With ws.Range("A6")
        .Value = ws.Range("B1")
        .Resize(ws.Range("B3") + 1).DataSeries
    End With
   
End Sub

Regards,

Robert
 
Last edited:
Upvote 0
Solution
Hi ColdSpirit,

Here's one way based on mirabeau's nifty solution from here that I was part of some years ago:

VBA Code:
Option Explicit
Sub Macro1()

    'Based on mirabeau's solution from https://www.mrexcel.com/board/threads/looping-x-number.579026

    Dim ws As Worksheet
  
    Set ws = ThisWorkbook.Sheets("047")
  
    With ws.Range("A6")
        .Value = ws.Range("B1")
        .Resize(ws.Range("B3") + 1).DataSeries
    End With
  
End Sub

Regards,

Robert
Really thank you for the help!
You made my day!

This works great!

God bless you!
 
Upvote 0

Similar threads

Forum statistics

Threads
1,223,884
Messages
6,175,174
Members
452,615
Latest member
bogeys2birdies

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