hello
I have this code . it populates values in textboxes and comboboxes after matching with sheets in COLS A,B,C,D,E,F) so what I want using loop to make the code is short
this is the code
I have this code . it populates values in textboxes and comboboxes after matching with sheets in COLS A,B,C,D,E,F) so what I want using loop to make the code is short
this is the code
VBA Code:
Private Sub CommandButton1_Click()
Dim ws As Worksheet
Dim Rng As Range
Dim Sel
Set ws = Sheets("first")
Sel = Me.ComboBox1.Value
If Sel <> "" Then
Set Rng = ws.Columns(4).Find(Sel, lookat:=xlWhole)
If Not Rng Is Nothing Then
ws.Cells(Rng.Row, "A") = Me.TextBox1.Value
ws.Cells(Rng.Row, "B") = Me.TextBox2.Value
ws.Cells(Rng.Row, "C") = Me.TextBox3.Value
ws.Cells(Rng.Row, "A") = Me.TextBox4Value
ws.Cells(Rng.Row, "B") = Me.TextBox5Value
ws.Cells(Rng.Row, "C") = Me.TextBox6Value
ws.Cells(Rng.Row, "A") = Me.TextBox7Value
ws.Cells(Rng.Row, "B") = Me.TextBox8Value
ws.Cells(Rng.Row, "C") = Me.TextBox9.Value
ws.Cells(Rng.Row, "D") = Me.ComboBox1.Value
ws.Cells(Rng.Row, "E") = Me.ComboBox2.Value
ws.Cells(Rng.Row, "F") = Me.CoMBoBoX3.Value
ws.Cells(Rng.Row, "D") = Me.ComboBox4.Value
ws.Cells(Rng.Row, "E") = Me.ComboBox5.Value
ws.Cells(Rng.Row, "F") = Me.CoMBoBoX6.Value
Else
Me.TextBox1.Value = ""
Me.TextBox2.Value = ""
Me.TextBox3.Value = ""
Me.TextBox4.Value ""
Me.TextBox5.Value = ""
Me.TextBox6.Value = ""
Me.TextBox7.Value = ""
Me.TextBox8.Value = ""
Me.TextBox9.Value = ""
Me.ComboBox1.Value = ""
Me.ComboBox2.Value = ""
Me.CoMBoboX3.Value = ""
Me.ComboBox4.Value = ""
Me.ComboBox5.Value = ""
Me.CoMBoBoX6.Value = ""
End If
End If
End Sub