Hello
I try to search for the last value for each item into sheet1,2 together .
if I have the same item for sheet1,2 , then should populate the value into textbox2 for last value is existed in last sheet based on selected combobox1 and optionbutton1 or optionbutton2 .
for example
CD-01 is existed in sheet1,2 for 10,11,12,14 then when populate the values in textbox2 after select combobox1,optionbutton1 ,then the values in textbox2 should be 14 .as to column G are 22,23,26,18 .if I select combobox1,optionbutton2 then the values in textbox2 should be 18
so if the item just repeat in the same sheet then should brings the last value for duplicates item in tje same sheet and if repeat for two sheets then should brings the last value from the last sheet
my code just work for the first sheet with ignore the second sheet .
Private Sub ComboBox1_Change()
Dim c As Range, rng As Range
Dim search As String
Dim ws As Variant
ws = Array("sheet1", "sheet2")
Set rng = Range("B2:B12")
search = Me.ComboBox1.Value
Set c = rng.Find(What:=search, LookIn:=xlValues, LookAt:=xlWhole, SearchDirection:=xlPrevious, MatchCase:=False, _
SearchFormat:=False)
For Each ws In rng
If Not c Is Nothing Then
'search value found
Me.ComboBox2.Value = c.Offset(, 1).Value
Me.ComboBox3.Value = c.Offset(, 2).Value
Me.ComboBox4.Value = c.Offset(, 3).Value
If Me.OptionButton1.Value = True Then
Me.TextBox2.Value = c.Offset(, 4).Value
ElseIf Me.OptionButton2.Value = True Then
Me.TextBox2.Value = c.Offset(, 5).Value
End If
End If
Next
End Sub
any suggetion would truly appreciated .