Hello! I am currently working on a project that requires me to insert data from a UserForm into the next blank row of an already created table. I first ran into the problem where it would only insert the new data from the UserForm into a newly created last row of the table, because some rows contain needed formulas. I was able to amend what the VBA I have to put the data into the next blank row, but only once. If I try to enter more data, it replaces only the first line in the table.
Hopefully this made sense. Summed up, I need to figure out how to amend my VBA code to allow a UserForm to populate input data into a table for the next blank row with formulas in different cells in the blank row. Below is my code so far. Like I said, everything works, except it only populates in the first row of the table, continuously replacing only the first row's data.
There are formulas in every cell besides the first in the included pictures. The first row starts in row 10. My range is SunSch which is my table name. I have to use the table name as my range so if there are more fields required, then the table can expand with the data.
I am continuing to try to figure it out, but any help would be greatly appreciated!
Thank you!!!
Hopefully this made sense. Summed up, I need to figure out how to amend my VBA code to allow a UserForm to populate input data into a table for the next blank row with formulas in different cells in the blank row. Below is my code so far. Like I said, everything works, except it only populates in the first row of the table, continuously replacing only the first row's data.
VBA Code:
Private Sub OKButton_Click()
Dim rng As Range
Set rng = ActiveSheet.ListObjects("SunSch").Range
Dim LastRow As Long
LastRow = rng.Find(What:="*", _
After:=rng.Cells(1), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).End(xlUp).Row
rng.Parent.Cells(LastRow + 1, 1).Value = StoreTextBox.Value
rng.Parent.Cells(LastRow + 1, 7).Value = TrailerTextBox.Value
rng.Parent.Cells(LastRow + 1, 8).Value = TractorTextBox.Value
rng.Parent.Cells(LastRow + 1, 9).Value = ProTextBox.Value
rng.Parent.Cells(LastRow + 1, 10).Value = LoadTextBox.Value
rng.Parent.Cells(LastRow + 1, 12).Value = DriverTextBox.Value
rng.Parent.Cells(LastRow + 1, 15).Value = StopTextBox.Value
rng.Parent.Cells(LastRow + 1, 19).Value = ConfirmedTextBox.Value
If DispatchCheck1.Value = True Then
rng.Parent.Cells(LastRow + 1, 11).Value = "Yes"
ElseIf DispatchCheck2.Value = True Then
rng.Parent.Cells(LastRow + 1, 11).Value = "No"
Else
rng.Parent.Cells(LastRow + 1, 11).Value = ""
End If
If InfoCheck1.Value = True Then
rng.Parent.Cells(LastRow + 1, 20).Value = "Yes"
ElseIf InfoCheck2.Value = True Then
rng.Parent.Cells(LastRow + 1, 20).Value = "No"
Else
rng.Parent.Cells(LastRow + 1, 20).Value = ""
End If
If LiveCheck1.Value = True Then
rng.Parent.Cells(LastRow + 1, 30).Value = "Yes"
ElseIf LiveCheck2.Value = True Then
rng.Parent.Cells(LastRow + 1, 30).Value = "No"
Else
rng.Parent.Cells(LastRow + 1, 30).Value = ""
End If
If CancelCheck1.Value = True Then
rng.Parent.Cells(LastRow + 1, 31).Value = "Yes"
ElseIf CancelCheck2.Value = True Then
rng.Parent.Cells(LastRow + 1, 31).Value = "No"
Else
rng.Parent.Cells(LastRow + 1, 31).Value = ""
End If
If SweepCheck1.Value = True Then
rng.Parent.Cells(LastRow + 1, 32).Value = "Yes"
ElseIf SweepCheck2.Value = True Then
rng.Parent.Cells(LastRow + 1, 32).Value = "No"
Else
rng.Parent.Cells(LastRow + 1, 32).Value = ""
End If
If RevCheck1.Value = True Then
rng.Parent.Cells(LastRow + 1, 33).Value = "Yes"
ElseIf RevCheck2.Value = True Then
rng.Parent.Cells(LastRow + 1, 33).Value = "No"
Else
rng.Parent.Cells(LastRow + 1, 33).Value = ""
End If
If BackhaulCheck1.Value = True Then
rng.Parent.Cells(LastRow + 1, 34).Value = "Yes"
ElseIf BackhaulCheck2.Value = True Then
rng.Parent.Cells(LastRow + 1, 34).Value = "No"
Else
rng.Parent.Cells(LastRow + 1, 34).Value = ""
End If
End Sub
There are formulas in every cell besides the first in the included pictures. The first row starts in row 10. My range is SunSch which is my table name. I have to use the table name as my range so if there are more fields required, then the table can expand with the data.
I am continuing to try to figure it out, but any help would be greatly appreciated!
Thank you!!!
Attachments
Last edited by a moderator: