VBA Userform Add Find next button and Fix Update button

ld00

New Member
Joined
Jul 31, 2022
Messages
1
Office Version
  1. 2013
  2. 2010
  3. 2007
Platform
  1. Windows
  2. MacOS
I have a worksheet that record label of some products that already assigned in 2 types, but the label numbers are duplicate so I want to add the Find next button to use when there is same label number in the worksheet with different type.
VBA Code:
Private Sub CommandButton1_Click() ' to search and display search button is pressed
labels As String
labels = Trim(Textbox1.Text)
lastRow = Worksheet("Sheet1").Cells(Row.Count, 2).End(xlUp).Row
For i = 2 to lastRow
If Worksheet("Sheet1").Cells(i, 2).Value = labels Then
Textbox2.Text = Worksheet("Sheet1").Cells(i, 1).Value 'company
Textbox3.Text = Worksheet("Sheet1").Cells(i, 3).Value 'type
Textbox4.Text= Worksheet("Sheet1").Cells(i, 4).Value 'date
Textbox5.Text = Worksheet("Sheet1").Cells(i, 5).Value 'used
Exit For
End If
Next
End Sub

Private Sub CommandButton2_Click() ' to Update information changed when button is pressed
labels As String
labels = Trim(Textbox1.Text)
lastRow = Worksheet("Sheet1").Cells(Row.Count, 2).End(xlUp).Row
For i = 2 to lastRow
If Worksheet("Sheet1").Cells(i, 2).Value = labels Then
Worksheet("Sheet1").Cells(i, 1).Value = Textbox2.Text'company
'Textbox3.Text = Worksheet("Sheet1").Cells(i, 3).Value 'type
Worksheet("Sheet1").Cells(i, 4).Value = Textbox4.Text 'date
Worksheet("Sheet1").Cells(i, 5).Value = Textbox5.Text 'used
Exit For
End If
Next
End Sub
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.

Forum statistics

Threads
1,214,899
Messages
6,122,155
Members
449,068
Latest member
shiz11713

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