Populate User Form Text Box with Data from Last Row of Table Column

dslaugh

New Member
Joined
Jul 16, 2020
Messages
4
Hello, as the title says, I would like to populate the text box of a UserForm1 data from the last row of the first column of the active worksheets table. The commented-out section is what I'm having a problem with. I want to pre-populate a couple textboxes in the form with editable data, and allow the user to finish the form, and post any changes within that same row.

VBA Code:
Sub ShowForm_Initialize()

Dim wb As Workbook
Dim ws As Worksheet
Dim NewRow As ListRow
Dim tbl As ListObject
Dim frm As UserForm1

Set wb = ThisWorkbook
Set ws = wb.Sheets("FY")
Set tbl = ws.ListObjects("Data")
    Set NewRow = tbl.ListRows.Add

With NewRow
.Range(6) = Now()
.Range(5) = tbl.DataBodyRange.Rows.Count
.Range(1).Value = NewRow.Range(4).Value & "-" & "DCATL" & "-" & NewRow.Range(3)
End With

'With frm
' .ShipmentIDTextBox.Value = tbl.DataBodyRange(??, 1).Value
'End With

UserForm1.Show

End Sub

Thank you,
Dan
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Hi & welcome to MrExcel.
Are you trying to get the value from the new row, or the previous row?
 
Upvote 0
In that case how about
VBA Code:
UserForm1.ShipmentIDTextBox.Value = NewRow.Range(1).Value
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,642
Messages
6,120,700
Members
448,979
Latest member
DET4492

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top