Autonumber in excel userform

Smalleyfamily

New Member
Joined
May 20, 2010
Messages
23
Hi,

I have a useform that I use to update a spreadsheet. What I would like to do is add an autonumber in column A (on a sheet called "BACS") when the data is saved "CmdSave".

The autonumber should be sequential, e.g. if the autonumber on the last entry is 56, then the autonumber for the new entry should be 57.

I hope you can help.

Regards,

Grant
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Try

Code:
Dim LR As Long
With Sheets("BACS")
    LR = .Range("A" & Rows.Count).End(xlUp).Row
    .Range("A" & LR + 1).Value = Range("A" & LR).Value + 1
End With
 
Upvote 0
Hi,

I've tried the code but with no joy. To be honest I am not sure where to place the code? Below is an extract of the code, can someone let me know where to add it?

P.S. I realised i'd need to look up column Q (15) rather than A and have changed the code that was provided but with no joy.

Private Sub Create_Click()<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
<o:p> </o:p>
Call UserForm_Initialize<o:p></o:p>
<o:p> </o:p>
End Sub<o:p></o:p>
<o:p> </o:p>
<o:p> </o:p>
<o:p> </o:p>
Private Sub cmdSubmit_Click()<o:p></o:p>
<o:p> </o:p>
Message.Visible = True<o:p></o:p>
<o:p> </o:p>
ActiveWorkbook.Sheets("BACS").Activate<o:p></o:p>
<o:p> </o:p>
Range("B2").Select<o:p></o:p>
<o:p> </o:p>
Do<o:p></o:p>
<o:p> </o:p>
If IsEmpty(ActiveCell) = False Then<o:p></o:p>
<o:p> </o:p>
ActiveCell.Offset(1, 0).Select<o:p></o:p>
<o:p> </o:p>
End If<o:p></o:p>
<o:p> </o:p>
Loop Until IsEmpty(ActiveCell) = True<o:p></o:p>
<o:p> </o:p>
ActiveCell.Value = txtSort.Value<o:p></o:p>
<o:p></o:p>
ActiveCell.Offset(0, 1) = txtAccount.Value<o:p></o:p>
<o:p> </o:p>
ActiveCell.Offset(0, 2) = txtAmount.Value<o:p></o:p>
<o:p></o:p>
ActiveCell.Offset(0, 3) = "<?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:eek:ffice:smarttags" /><st1:place w:st="on">Mobile</st1:place> Device Ins"<o:p></o:p>
<o:p></o:p>
ActiveCell.Offset(0, 5) = txtCusname.Value<o:p></o:p>
<o:p></o:p>
ActiveCell.Offset(0, 4) = txtPolno.Value<o:p></o:p>
<o:p></o:p>
ActiveCell.Offset(0, 6) = PolicyType.Value<o:p></o:p>
<o:p></o:p>
ActiveCell.Offset(0, 7) = cboBusp.Value<o:p></o:p>
<o:p></o:p>
ActiveCell.Offset(0, 8) = BP.Value<o:p></o:p>
<o:p></o:p>
ActiveCell.Offset(0, 9) = cboChequeReason.Value<o:p></o:p>
<o:p> </o:p>
ActiveCell.Offset(0, 10) = Authorisation.Value<o:p></o:p>
<o:p> </o:p>
ActiveCell.Offset(0, 11) = Make.Value<o:p></o:p>
<o:p> </o:p>
ActiveCell.Offset(0, 12) = Model.Value<o:p></o:p>
<o:p></o:p>
ActiveCell.Offset(0, 13) = fOSUserName<o:p></o:p>
<o:p> </o:p>
ActiveCell.Offset(0, 14) = Now()<o:p></o:p>
<o:p></o:p>
<o:p> </o:p>
<o:p> </o:p>
<o:p> </o:p>
End Sub<o:p></o:p>
 
Upvote 0
Try

Code:
Private Sub cmdSubmit_Click()
Dim LR As Long
Message.Visible = True
With Sheets("BACS")
    LR = .Range("A" & Rows.Count).End(xlUp).Row
    .Range("A" & LR + 1).Value = Range("A" & LR).Value + 1
    LR = .Range("B" & Rows.Count).End(xlUp).Row + 1
    .Cells(LR, 2).Value = txtSort.Value
    .Cells(LR, 3).Value = txtAccount.Value
    .Cells(LR, 4).Value = txtAmount.Value
    .Cells(LR, 5).Value = "Mobile Device Ins"
    .Cells(LR, 6).Value = txtCusname.Value
    .Cells(LR, 7).Value = txtPolno.Value
    .Cells(LR, 8).Value = PolicyType.Value
    .Cells(LR, 9).Value = cboBusp.Value
    .Cells(LR, 10).Value = BP.Value
    .Cells(LR, 11).Value = cboChequeReason.Value
    .Cells(LR, 12).Value = Authorisation.Value
    .Cells(LR, 13).Value = Make.Value
    .Cells(LR, 14).Value = Model.Value
    .Cells(LR, 15).Value = fOSUserName
    .Cells(LR, 16).Value = Now
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,751
Messages
6,126,669
Members
449,326
Latest member
asp123

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