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