hi
I try finding way to fill data in specific sheet . when I select the name from combobox should match with the names are existed in COL B then insert a new row and fill data but the problem it left the rows have empty from COL C: F what i want before insert row should look for the row is empty from col c : f then should fill if there is no value from column c: f then should insert the row and fill as the code works
thanks in advance
I try finding way to fill data in specific sheet . when I select the name from combobox should match with the names are existed in COL B then insert a new row and fill data but the problem it left the rows have empty from COL C: F what i want before insert row should look for the row is empty from col c : f then should fill if there is no value from column c: f then should insert the row and fill as the code works
VBA Code:
Private Sub CommandButton1_Click()
Dim ws As Worksheet, Rng As Range, Sel As Variant
Set ws = Sheets("sheet1")
Sel = Me.ComboBox1.Value
If Sel <> "" Then
Set Rng = ws.Columns(2).Find(Sel, lookat:=xlWhole, searchdirection:=xlPrevious) 'search backawrds!
If Not Rng Is Nothing Then
Cells(Rng.Row + 1, "A").Resize(1, 6).Insert Shift:=xlDown, _
CopyOrigin:=xlFormatFromLeftOrAbove
ws.Cells(Rng.Row + 1, "A") = Now
ws.Cells(Rng.Row + 1, "B") = Sel
ws.Cells(Rng.Row + 1, "C") = Me.TextBox1.Value
ws.Cells(Rng.Row + 1, "D") = Me.TextBox2.Value
ws.Cells(Rng.Row + 1, "E") = Me.TextBox3.Value
ws.Cells(Rng.Row + 1, "F") = Me.TextBox4.Value
End If
End If
Unload Me
End Sub