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
 

Some videos you may like

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
53,349
Office Version
  1. 365
Platform
  1. Windows
Hi & welcome to MrExcel.
Are you trying to get the value from the new row, or the previous row?
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
53,349
Office Version
  1. 365
Platform
  1. Windows
In that case how about
VBA Code:
UserForm1.ShipmentIDTextBox.Value = NewRow.Range(1).Value
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
53,349
Office Version
  1. 365
Platform
  1. Windows
You're welcome & thanks for the feedback.
 

Watch MrExcel Video

Forum statistics

Threads
1,123,456
Messages
5,601,772
Members
414,472
Latest member
Chris_1990

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
Top