Please I have a Userform with combobox1, combobox2 and Textbox1, and the associated Sheet is "sample". Tabulated data in the Sheet is shown below:
A B C R
1 AB001 T21 25
2 AB001 T22 25
3 AB003 T23 20
4 AB003 T24 20
5 AB003 T25 20
6 AB002 T26 15
7 AB001 T27 25
8 AB003 T28 20
At a click of a button, I want to compare combobox1 value (string) with values in column B, and a match is found, those values (in column B) should be replaced with combobox2 value and the corresponding rows in column R should be replaced with Textbox1 value. For example, given that combobox1.Value = "AB003", combobox2.Value = "AB005" and Textbox1.Value = 32, then
1. Replace Rows 3, 4, 5 & 8 of column B with "AB005"
2. Replace Rows 3, 4, 5 & 8 of column R with 32
Please your help will be greatly appreciated.
I have tried the code below and it is not working for me:
Dim Lastrow As Long, ws As Worksheet
Set ws = Worksheets("sample")
Lastrow = ws.Cells(Rows.Count, "A").End(xlUp).Row
For i = 2 To Lastrow
If Not IsError(Application.Match(Trim(Me.Combobox1.Value), ws.Range("B:B"), 0)) Then
ws.Cells(i, "B").Value = Me.Combobox2.Value.Value
ws.Cells(i, "R").Value = Me.Textbox1.Value
End If
Next i
A B C R
1 AB001 T21 25
2 AB001 T22 25
3 AB003 T23 20
4 AB003 T24 20
5 AB003 T25 20
6 AB002 T26 15
7 AB001 T27 25
8 AB003 T28 20
At a click of a button, I want to compare combobox1 value (string) with values in column B, and a match is found, those values (in column B) should be replaced with combobox2 value and the corresponding rows in column R should be replaced with Textbox1 value. For example, given that combobox1.Value = "AB003", combobox2.Value = "AB005" and Textbox1.Value = 32, then
1. Replace Rows 3, 4, 5 & 8 of column B with "AB005"
2. Replace Rows 3, 4, 5 & 8 of column R with 32
Please your help will be greatly appreciated.
I have tried the code below and it is not working for me:
Dim Lastrow As Long, ws As Worksheet
Set ws = Worksheets("sample")
Lastrow = ws.Cells(Rows.Count, "A").End(xlUp).Row
For i = 2 To Lastrow
If Not IsError(Application.Match(Trim(Me.Combobox1.Value), ws.Range("B:B"), 0)) Then
ws.Cells(i, "B").Value = Me.Combobox2.Value.Value
ws.Cells(i, "R").Value = Me.Textbox1.Value
End If
Next i