Hi,
I have created a database, where data from the userform is entered into the Worksheet ("data_entry") into the respective column.
Now I want to load counter readings (in a production of components) automatically into the Userform.
As soon as the respective component is selected via the "Combobox5", and then the Side (in this case left / right) is selected,
the last counter reading of the respective Side of the Component is entered in the "Textbox19".
I have put together something that works roughly, but it only searches for the name of the component (Combobox5), not the respective Side (Combobox8).
This means that it only works according to the criterion "Component 1".
I have already looked in several forums for similar problems, but have not found anything similar.
I would be very grateful if someone can help me.
Here is the Code:
I have created a database, where data from the userform is entered into the Worksheet ("data_entry") into the respective column.
Now I want to load counter readings (in a production of components) automatically into the Userform.
As soon as the respective component is selected via the "Combobox5", and then the Side (in this case left / right) is selected,
the last counter reading of the respective Side of the Component is entered in the "Textbox19".
I have put together something that works roughly, but it only searches for the name of the component (Combobox5), not the respective Side (Combobox8).
This means that it only works according to the criterion "Component 1".
I have already looked in several forums for similar problems, but have not found anything similar.
I would be very grateful if someone can help me.
Here is the Code:
VBA Code:
'Component 1
'load the last Counter 'End'-Entry for Component 1
If ComboBox5.Text = "Component 1" and Combobox8.Text = "Left" Then
Dim cpnt1 As Range
Dim side_left As Range
Set cpnt1 = Worksheets("data_entry").Range("F:M").Find(what:="Component 1", LookAt:=xlWhole, SearchDirection:=xlPrevious) 'search for "Component1" in the last line of sheets "data_entry"
Set side_left = Worksheets("data_entry").Range("F:M").Find(what:="Left", LookAt:=xlWhole, SearchDirection:=xlPrevious) 'search for "Left" in the last line of sheets "data_entry"
With Sheets("data_entry")
On Error GoTo nofound_cpnt1: 'in case no begin or end was found, goto "nofound_cpnt1:"
If cpnt1.Cells.Offset(0, 6).Value = "" Then 'if End is empty
TextBox19.Text = cpnt1.Offset(0, 5).Value 'take counter begin, if available
Else 'Else = if cell is not empty
TextBox19.Text = cpnt1.Offset(0, 6).Value 'take counter end, if available
End If
End With
nofound_cpnt1: 'let "Textbox19" empty
'do nothing
End If