Run Multiple Command Buttons in order

krasnick

New Member
Joined
Dec 20, 2018
Messages
2
I'm new to vba and need help with a vba script. I have two command buttons that were created within a UserForm1. I've tried to run the second by using "Call", but it does not work. Is there a way to run button 1 first, then button 2 immediately after 1?


Public Sub CommandButton1_Click()
Dim LastRow As Long, ws As Worksheet


Set ws = Sheets("CIF")


LastRow = ws.Range("A" & Rows.Count).End(xlUp).Row + 1


ws.Range("A" & LastRow).Value = TextBox1.Text

Public Sub CommandButton2_Click()
Dim i As Long, LastRow As Long, ws As Worksheet
Set ws = Sheets("CIF")
LastRow = ws.Range("A" & Rows.Count).End(xlUp).Row


For i = 2 To LastRow
If (Me.TextBox1.Text) = ws.Cells(i, "A") Then
Me.TextBox2 = ws.Cells(i, "B").Value






End Sub

Public Sub CommandButton2_Click()
Dim i As Long, LastRow As Long, ws As Worksheet
Set ws = Sheets("CIF")
LastRow = ws.Range("A" & Rows.Count).End(xlUp).Row


For i = 2 To LastRow
If (Me.TextBox1.Text) = ws.Cells(i, "A") Then
Me.TextBox2 = ws.Cells(i, "B").Value

End If
Next i

End Sub
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Button 1 is using a textbox to save the customer number to column A of worksheet. The worksheet has a vlookup formula in columns B-D to another Excel file that returns the customer address. Button 2 uses the values in columns B-D to populate the remaining textboxes on the userform.
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,912
Members
452,366
Latest member
TePunaBloke

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