UserForm VBA Coding - Update command button

Copper Contributor

Hello 

I was wondering if someone may be able to help me to restrict the following code to only updating one record within a Excel UserForm.  At present I have a search function which finds a name within textbox2 for eg. Bill.  I alter the data that is populated in the form as required however when I select Update it updates all the "Bill's" within the spreadsheet rather than just the one that is loaded into the form.

Any advice would be greatly appreciated.

 

My code is as follows:

Private Sub CommandButton6_Click()
Dim Name As String
Name = Trim(TextBox2.Text)
lastrow = Worksheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To lastrow
If Worksheets("Sheet1").Cells(i, 2).Value = TextBox2 Then
Worksheets("Sheet1").Cells(i, 3) = TextBox3.Text 
Worksheets("Sheet1").Cells(i, 4) = TextBox4.Text 
Worksheets("Sheet1").Cells(i, 5) = TextBox5.Text 
Worksheets("Sheet1").Cells(i, 6) = TextBox6.Text 
Worksheets("Sheet1").Cells(i, 7) = TextBox7.Text 
Worksheets("Sheet1").Cells(i, 8) = Recommendations.Value 

End If
Next
End Sub

 

 

1 Reply

@Nicisherre 

How can we determine which row (record) is currently loaded?