sspatriots
Well-known Member
- Joined
- Nov 22, 2011
- Messages
- 585
- Office Version
- 365
- Platform
- Windows
From all the help in the post below from "RoryA", I was able to successfully pull data into a Userform by referencing table column headers:
Is it possible to write code to modify code for new columns?
Now I have attempted to reverse the process to allow the user to select an "Update" button on the Userform and update the table directly from the form using the same code in reverse. However, it is giving me a "Run-time error '424': Object required" message at the line that starts with ".tb.ListColumns...". Not sure what object it is looking for here. Thanks in advance for any attention given to this post.
Is it possible to write code to modify code for new columns?
Now I have attempted to reverse the process to allow the user to select an "Update" button on the Userform and update the table directly from the form using the same code in reverse. However, it is giving me a "Run-time error '424': Object required" message at the line that starts with ".tb.ListColumns...". Not sure what object it is looking for here. Thanks in advance for any attention given to this post.
VBA Code:
Sub Update_Job_Status_Form()
Dim wb As Workbook
Dim ws As Worksheet 'Added SPS,06/16/22
Dim tb As ListObject
Dim frm As Object 'UserForm
Dim job_name As String
Dim i As Long
Set wb = ThisWorkbook
Set ws = wb.Sheets("Jobs") 'Added SPS,06/16/22, worksheet the table is on
Set tb = ws.ListObjects("G2JobList")
Set frm = Job_Status
With frm
job_name = Trim(.txtJobName.Text)
For i = 1 To tb.DataBodyRange.Rows.Count
If tb.ListColumns("Job Name").DataBodyRange.Cells(i).Value = job_name Then
.tb.ListColumns("Job" & Chr(10) & "Status").DataBodyRange.Cells(i).Value = cboJobStatus.Text
.tb.ListColumns("G2" & Chr(10) & "PM").DataBodyRange.Cells(i).Value = txtG2PM.Text
Exit For
End If
Next
End With
NumLockCorrector
End Sub