simple sequential numbers in VBA

epardo87

Board Regular
Joined
Feb 24, 2015
Messages
56
Hello,

I need to place a simple sequential number in a cell, I searched a lot but couldn't find something as simple as I need:

Cells(emptyRow, 2).Value = ????

Thanks!
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Are you trying to increment the existing number? If so try this:

Code:
With Cells(emptyRow,2)
.Value = .Value+1
End With
 
Upvote 0
Thanks, yes i'm trying to increment existing number. The file already has previous serial numbers which were filled by hand beginning from 1000000.

Every entry is transferred into a new row and I need the serial number to be pasted in the column B

I pasted it just as you wrote it but it only places "1" and doesn't increment it in subsequent entries.

I don't know much but wouldn't we need to make some kind of reference in .value = .value + 1 to use the value of previous row? I'm guessing that is why it keeps giving "1"
 
Last edited:
Upvote 0
Which cell currently has the value in?
Which cell are you trying to increment?
 
Upvote 0
last entry has serial number 1000050 in B52, a new entry should place 1000051 in B53
 
Upvote 0
Well, nothing yet, I thought I could place certain code after that for the serial number, like in the other cells ... look here a simplified version of the complete code, everything works fine, I just have this code left to solve (the code I'm asking about is almost at the end):
Code:
[COLOR=#0000ff]Private Sub [/COLOR]RegCommandButton_Click()

[COLOR=#0000ff]Dim [/COLOR]emptyRow [COLOR=#0000ff]As Long[/COLOR]

[COLOR=#008000]'Make Sheet2 active[/COLOR]
Sheet2.Activate

[COLOR=#008000]'Determine emptyRow[/COLOR]
emptyRow = WorksheetFunction.CountA(Range("A:A")) + 1

[COLOR=#008000]'Transfer information[/COLOR]

[COLOR=#0000ff]Dim [/COLOR]bControlEmpty [COLOR=#0000ff]As Boolean[/COLOR]

bControlEmpty = [COLOR=#0000ff]False[/COLOR]

    If Len(ItemComboBox.Value) > 0 [COLOR=#0000ff]Then[/COLOR]
    Cells[B](emptyRow, 3)[/B].Value = ItemComboBox.Value
    [COLOR=#0000ff]Else[/COLOR]
    bControlEmpty = [COLOR=#0000ff]True[/COLOR]
    [COLOR=#0000ff]End If[/COLOR]
    If Len(QtyTextBox.Value) > 0 [COLOR=#0000ff]Then[/COLOR]
    Cells[B](emptyRow, 4)[/B].Value = QtyTextBox.Value
    [COLOR=#0000ff]Else[/COLOR]
    bControlEmpty = [COLOR=#0000ff]True[/COLOR]
    [COLOR=#0000ff]End If[/COLOR]
    If Len(AreaComboBox.Value) > 0 [COLOR=#0000ff]Then[/COLOR]
    Cells[B](emptyRow, 5)[/B].Value = AreaComboBox.Value
    [COLOR=#0000ff]Else[/COLOR]
    bControlEmpty = [COLOR=#0000ff]True[/COLOR]
  [COLOR=#0000ff]  End If[/COLOR]
    If Len(CauseComboBox.Value) > 0 [COLOR=#0000ff]Then[/COLOR]
    Cells[B](emptyRow, 6)[/B].Value = CauseComboBox.Value
    [COLOR=#0000ff]Else[/COLOR]
    bControlEmpty = [COLOR=#0000ff]True[/COLOR]
    [COLOR=#0000ff]End If[/COLOR]
    
[COLOR=#0000ff]If [/COLOR]bControlEmpty [COLOR=#0000ff]Then[/COLOR]
    MsgBox "Please complete the form"
[COLOR=#0000ff]Else[/COLOR]
    
   Cells[B](emptyRow, 1)[/B].Value = Date
[COLOR=#ff0000][B]    With Cells(emptyRow, 2)[/B]
[B]    .Value = .Value + 1[/B]
[B]    End With[/B][/COLOR]

    ThisWorkbook.Save
    Unload Me
    
[COLOR=#0000ff] End If

End Sub[/COLOR]
 
Last edited:
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,176
Members
451,543
Latest member
cesymcox

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