I would like to insert a value in to the last row available according to my combox

Viewed 25

hope you are doing well! I have a form where you can add someone who works for a specific clients. So, in my combobox you have a list of clients, you can choose and then in a textbox, you can put the first and last name of a worker . I would like for the code to find in the database, the client chosen in the combobox and then after all workers already put in place, insert the first and last name of the new worker.

Here what I tried : (the part for the combobox work but for the new employee it does not work.)

Private Sub Userform_Initialize()
Dim i As Integer
Worksheets("Database").Select
For i = 1 To 4000
ComboBox1.AddItem Cells(1, i)
Next
End Sub
Private Sub CommandButton1_Click()
Dim cell As Range
Dim var As String
Dim rw As Integer
Dim field_search As Range
Worksheets("Database").Select
Set field_search = Range("A1", Range("A1").End(xlToRight))
For Each cell In field_search
If cell.Value = ComboBox1.Value Then
cell.EntireColumn.Select
rw = cell.Cells.Find(What:=" ", SearchOrder:=xlRows, SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1
cell.Cells(2, rw).Value = TextBox4 + " " + TextBox3
cell.Cells(3, rw).Value = TextBox2 + " " + TextBox5
cell.Cells(4, rw).Value = TextBox6 + " " + TextBox7
End If
Next
End Sub

If you have an idea, I am all ears !

0 Answers
Related