skeeeter56
New Member
- Joined
- Nov 26, 2016
- Messages
- 42
- Office Version
- 2019
- Platform
- Windows
I know how to add data to a table from a user form, can you do same thing from the values in cells on another worksheet when you click a button.
The above is the code when using a user form this all works.
But as there are calculations done based on what is inputted in, the results of which I want to save in a table and than clear the cells that have been inputed.
So is there a way I can get the values stored in certain cells to add into the fields on the table.
Code:
Dim lrow As Range
Dim lrow2 As Long
Set tbl = Sheets("PRP History").ListObjects("tblPRP")
If tbl.ListRows.Count > 0 Then
Set lrow = tbl.ListRows(tbl.ListRows.Count).Range
For col = 1 To lrow.Columns.Count
If Trim(CStr(lrow.Cells(1, col).Value)) <> "" Then
tbl.ListRows.Add
Exit For
End If
Next
End If
lrow2 = tbl.ListRows.Count
tbl.DataBodyRange(lrow2, 1).Value = cboEmployee.Value
tbl.DataBodyRange(lrow2, 2).Value = txtDate.Value
tbl.DataBodyRange(lrow2, 3).Value = cboRound.Value
tbl.DataBodyRange(lrow2, 4).Value = TextBox1.Value
tbl.DataBodyRange(lrow2, 5).Value = TextBox2.Value
tbl.DataBodyRange(lrow2, 6).Value = TextBox3.Value
tbl.DataBodyRange(lrow2, 7).Value = TextBox4.Value
tbl.DataBodyRange(lrow2, 8).Value = TextBox5.Value
tbl.DataBodyRange(lrow2, 9).Value = TextBox6.Value
tbl.DataBodyRange(lrow2, 10).Value = TextBox7.Value
tbl.DataBodyRange(lrow2, 11).Value = TextBox8.Value
tbl.DataBodyRange(lrow2, 12).Value = TextBox9.Value
tbl.DataBodyRange(lrow2, 13).Value = TextBox10.Value
tbl.DataBodyRange(lrow2, 14).Value = TextBox11.Value
tbl.DataBodyRange(lrow2, 15).Value = TextBox12.Value
Unload Me
End Sub
The above is the code when using a user form this all works.
But as there are calculations done based on what is inputted in, the results of which I want to save in a table and than clear the cells that have been inputed.
So is there a way I can get the values stored in certain cells to add into the fields on the table.