VBA adding value by 1

quarna

New Member
Joined
Oct 25, 2021
Messages
38
Office Version
  1. 365
Platform
  1. Windows
Hi

column A has a range of values like this
B20210188
B20210189
B20210190
B20210191
B20210192
B20220000
B20220001
B20220002
B20220003
B20220004
B20220005
B20220006
B20220007
B20220008
B20220009
B20220010
B20220011
B20220012

I have a userform with values im adding to a datasheet with this code

Cells(Rows.Count, 1).End(xlUp)(2) = UserForm1.TextBox1.Text
Cells(Rows.Count, 1).End(xlUp).Offset(0, 1) = UserForm1.TextBox2.Text
Cells(Rows.Count, 1).End(xlUp).Offset(0, 2) = UserForm1.ComboBox2.Text
Cells(Rows.Count, 1).End(xlUp).Offset(0, 3) = UserForm1.TextBox4.Text
Cells(Rows.Count, 1).End(xlUp).Offset(0, 4) = UserForm1.ComboBox3.Text
Cells(Rows.Count, 1).End(xlUp).Offset(0, 5) = UserForm1.TextBox6.Text
Cells(Rows.Count, 1).End(xlUp).Offset(0, 6) = UserForm1.TextBox7.Text
Cells(Rows.Count, 1).End(xlUp).Offset(0, 7) = UserForm1.TextBox8.Text
Cells(Rows.Count, 1).End(xlUp).Offset(0, 8) = UserForm1.TextBox9.Text
Cells(Rows.Count, 1).End(xlUp).Offset(0, 9) = UserForm1.ComboBox1.Text
Cells(Rows.Count, 1).End(xlUp).Offset(0, 10) = UserForm1.TextBox11.Text
Cells(Rows.Count, 1).End(xlUp).Offset(0, 11) = UserForm1.TextBox12.Text

Textbox 1 contains the row A values
I want when i open the userform to have the next number to be shown in textbox1

Like if lastline in column A is B20220012
The textbox1 should contain B20220013 when userform1.show is executed.

thank you
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
try
VBA Code:
Private Sub UserForm_Initialize()
    
    Dim lastA As String
    
lastA = Cells(Rows.Count, 1).End(xlUp).Value
Me.TextBox1 = Left(lastA, 1) & (Mid(lastA, 2) + 1)

End Sub
 
Upvote 0
Solution
try
VBA Code:
Private Sub UserForm_Initialize()
   
    Dim lastA As String
   
lastA = Cells(Rows.Count, 1).End(xlUp).Value
Me.TextBox1 = Left(lastA, 1) & (Mid(lastA, 2) + 1)

End Sub

Amazing, thank you.

I did have to change Me.TextBox1 =
to UserForm1.TextBox1 =
for it to work though

Have a nice day
 
Upvote 0

Forum statistics

Threads
1,215,734
Messages
6,126,542
Members
449,316
Latest member
sravya

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