введите описание изображения здесь
Вот мой код ниже:
*Private Sub CommandButton8_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Summary")
Dim rngNullString
'find first empty row in database
Set rngNullString = Intersect(ws.Columns("B"), ws.Columns("B")).Find("")
If rngNullString.Row < ws.Cells(ws.Rows.Count, "B").End(xlUp).Row Then
Set rngNullString = Intersect(ws.Columns("B"), ws.Columns("B")).SpecialCells(xlCellTypeBlanks)
End If
iRow = rngNullString.Row
' iRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _
' SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1
'check for Name number
If Trim(Me.ComboBox1.Value) = "" Then
Me.ComboBox1.SetFocus
MsgBox "Please complete the FORM"
Exit Sub
End If
'copy the data to the database
ws.Cells(iRow, 2).Value = Me.ComboBox21.Value
ws.Cells(iRow, 4).Value = Me.ComboBox39.Value
ws.Cells(iRow, 5).Value = Me.TextBox8.Value
ws.Cells(iRow, 6).Value = Me.TextBox9.Value
ws.Cells(iRow, 7).Value = Me.TextBox112.Value
ws.Cells(iRow, 2).Value = Me.ComboBox22.Value
ws.Cells(iRow, 4).Value = Me.ComboBox40.Value
ws.Cells(iRow, 5).Value = Me.TextBox11.Value
ws.Cells(iRow, 6).Value = Me.TextBox15.Value
ws.Cells(iRow, 7).Value = Me.TextBox113.Value
ws.Cells(iRow, 2).Value = Me.ComboBox23.Value
ws.Cells(iRow, 4).Value = Me.ComboBox41.Value
ws.Cells(iRow, 5).Value = Me.TextBox17.Value
ws.Cells(iRow, 6).Value = Me.TextBox21.Value
ws.Cells(iRow, 7).Value = Me.TextBox114.Value
ws.Cells(iRow, 2).Value = Me.ComboBox24.Value
ws.Cells(iRow, 4).Value = Me.ComboBox42.Value
ws.Cells(iRow, 5).Value = Me.TextBox23.Value
ws.Cells(iRow, 6).Value = Me.TextBox27.Value
ws.Cells(iRow, 7).Value = Me.TextBox115.Value
ws.Cells(iRow, 2).Value = Me.ComboBox25.Value
ws.Cells(iRow, 4).Value = Me.ComboBox43.Value
ws.Cells(iRow, 5).Value = Me.TextBox29.Value
ws.Cells(iRow, 6).Value = Me.TextBox33.Value
ws.Cells(iRow, 7).Value = Me.TextBox116.Value
ws.Cells(iRow, 2).Value = Me.ComboBox26.Value
ws.Cells(iRow, 4).Value = Me.ComboBox44.Value
ws.Cells(iRow, 5).Value = Me.TextBox35.Value
ws.Cells(iRow, 6).Value = Me.TextBox39.Value
ws.Cells(iRow, 7).Value = Me.TextBox117.Value
MsgBox "Data added", vbOKOnly + vbInformation, "Data Added"
'clear the data
End Sub*
** Мой код не работает, можно добавить только 1 строку. Данные находятся в тех же столбцах, но в разных строках. Как вы можете видеть ниже (прикрепленное фото), если я добавлю значение в свое поле со списком и текстовое поле, я захочу добавить несколько данных в строки соответственно.