Sequential number generation

Paul15

New Member
Joined
Jun 25, 2020
Messages
44
Office Version
  1. 2019
Platform
  1. Windows
Hi Team,

I have used the code in question 965869 and can get a sequential number to populate via my user form to the required location on the spreadsheet, however this is writing to the spreadsheet before the other entered data is submitted to the sheet via the command button. This is forcing my remaining data to populate 1 line below the sequential number. Code is:

Private Sub CommandButton1_Click()
With ThisWorkbook.Worksheets("Sheet1")
.Cells(.Rows.Count, "A").End(xlUp).Offset(1) = TextBox1.Value
TextBox1.Text = Application.Max(.Range("A:A")) + 1
End With
End Sub

Private Sub UserForm_Initialize()
With ThisWorkbook.Worksheets("Sheet1")
TextBox1.Text = Application.Max(.Range("A:A")) + 1
End With
End Sub

If we can maybe change the sequence of events such that the generated number does not write to the sheet until the command button is pressed I think this might fix it

Any help please
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Comment out the code within the Private Sub UserForm_Initialze() Use Rem or ' apostrophe

VBA Code:
Rem  With ThisWorkbook.Worksheets("Sheet1")
Rem        TextBox1.Text = Application.Max(.Range("A:A")) + 1
Rem    End With
 
Upvote 0
Hi & welcome to MrExcel
This is the code that is writting to the sheet
VBA Code:
Private Sub CommandButton1_Click()
   With ThisWorkbook.Worksheets("Sheet1")
       .Cells(.Rows.Count, "A").End(xlUp).Offset(1) = TextBox1.Value
       TextBox1.Text = Application.Max(.Range("A:A")) + 1
   End With
End Sub
If you remove it then you should be ok.
 
Upvote 0
Hi Trevor,

commenting out the code as suggested stops the remaining code from working. I no longer have a generated number

I have got it to work, but on clicking the command button to submit the updates from the form to the sheet, the sequence number seems to write first; on a blank sheet, A1, the remainder of the submitted data goes to Row 2. This would make sense as the VBA is trying to write data and will always write to the next blank row. As the sequential number had filled a row then the codec writes to the next row down. What I wish to happen is all data is written at the same time with the sequential number and data entering sequentially.

Regards
 
Upvote 0
Fluff, I have astrixed out the code as you suggest, however whilst my data goes to the correct place, the sequential number i wish to be sent to the sheet and sequentially done so for every data input

Regards
 
Upvote 0
In that case you will need to add that code, to the code which updates your sheet.
 
Upvote 0
Hi. I have a worksheet with data being entered via a user form. This uses a command button ( submit button) to submit data to sheet. I wish to have a sequential number added to each new row of data; my sheet this will be at column AS of whatever row the new data is copied to upon activation of the command / submit button.
The number must increment by 1 for each new row from a predetermined start value, say 120000.
The number must remain sequential no matter if the form is closed or cleared before submission, last number, eg 120010, form cleared or closed, reopened next number 120011
All data should write to the sheet at the same time and all be on the same row

Regards
 
Upvote 0
What code do you have for adding the values to the sheet?
 
Upvote 0
What code do you have for adding the values to the sheet?
Code is below. I found this in an earlier question.

On the user form there is a text box called SQNum, a sequential number is seen here. Other data fields are entered in the various other areas of the user form. Upon clicking the Command Button to submit all the data to the sheet ‘IS81s’ the sequential number goes to the sheet at AS1, the remaining data goes to row 2.
I need all data to appear on the same row


Private Sub CommandButton1_Click()
With ThisWorkbook.Worksheets("IS81s")
.Cells(.Rows.Count, "AS").End(xlUp).Offset(1) = SQNum.Value
SQNum.Text = Application.Max(.Range("AS:AS”)) + 1
End With
End Sub

Private Sub UserForm_Initialize()
With ThisWorkbook.Worksheets("IS81s")
SQNum.Text = Application.Max(.Range("AS:AS”)) + 1
End With
End Sub
 
Upvote 0
That code only adds the SQNum to the sheet nothing else. Please post the code that puts the rest of the data to the sheet.
 
Upvote 0

Forum statistics

Threads
1,213,557
Messages
6,114,293
Members
448,564
Latest member
ED38

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