I have a userform where its data populate in different tables of the same worksheet. A combox in the Userform has lists of table names and I want any table name selected from the combobox to set focus the particular table the data will be populated.
I have INVENTORY1, INVENTORY2, INVENTORY3 and INVENTORY4 as table names represented in combobox1.
When I run my userform My VBA code below shows Compile error: Method or data member not found and .ListObject highlighted blue along side Private Sub CommandButton1_Click() in yellow color.
PLEASE I NEED HELP.
My codes below:
Private Sub CommandButton1_Click()
Dim the_sheet As Worksheet
Dim table_list_object As ListObject
Dim table_object_row As ListRow
Set the_sheet = Sheets("ALL USAGES")
Set table_list_object = the_sheet.ListObject("INVENTORY1", "INVENTORY2")
Set table_object_row = table_list_object.ListRows.Add
If statuscombobox1.Value = "INVENTORY1" Then
ListObjects = "INVENTORY1"
Else
If statuscombobox1.Value = "INVENTORY2" Then
ListObjects = "INVENTORY2"
Else
If statuscombobox1.Value = "INVENTORY3" Then
ListObjects = "INVENTORY3"
Else
If statuscombobox1.Value = "INVENTORY4" Then
ListObjects = "INVENTORY4"
End If
End If
End If
End If
table_object_row.Range("INVENTORY1", 1).Value = ComboBox1.Value
last_row_with_data = the_sheet.Range("A" & Rows.Count).End(xlUp).Row
Sheets("ALL USAGES").Cells(lastrow + 1, "A").Value = TextBox1.text
Sheets("ALL USAGES").Cells(lastrow + 1, "B").Value = TextBox2.text
Sheets("ALL USAGES").Cells(lastrow + 1, "C").Value = TextBox3.text
Sheets("ALL USAGES").Cells(lastrow + 1, "D").Value = TextBox4.text
Sheets("ALL USAGES").Cells(lastrow + 1, "D").Columns.AutoFit
MsgBox ("Data is added successfully")
TextBox1.Value = ""
TextBox2.Value = ""
TextBox3.Value = ""
TextBox4.Value = ""
ComboBox1.Value = ""
Worksheets("DASHBOARD").Activate
Worksheets("DASHBOARD").Cells(1, 1).Select
End Sub
Private Sub UserForm_Initialize()
ComboBox1.Value = SetFocus
TextBox2.text = Date
ComboBox1.List = Array("INVENTORY1", "INVENTORY2", "INVENTORY3", "INVENTORY4")
End Sub
I have INVENTORY1, INVENTORY2, INVENTORY3 and INVENTORY4 as table names represented in combobox1.
When I run my userform My VBA code below shows Compile error: Method or data member not found and .ListObject highlighted blue along side Private Sub CommandButton1_Click() in yellow color.
PLEASE I NEED HELP.
My codes below:
Private Sub CommandButton1_Click()
Dim the_sheet As Worksheet
Dim table_list_object As ListObject
Dim table_object_row As ListRow
Set the_sheet = Sheets("ALL USAGES")
Set table_list_object = the_sheet.ListObject("INVENTORY1", "INVENTORY2")
Set table_object_row = table_list_object.ListRows.Add
If statuscombobox1.Value = "INVENTORY1" Then
ListObjects = "INVENTORY1"
Else
If statuscombobox1.Value = "INVENTORY2" Then
ListObjects = "INVENTORY2"
Else
If statuscombobox1.Value = "INVENTORY3" Then
ListObjects = "INVENTORY3"
Else
If statuscombobox1.Value = "INVENTORY4" Then
ListObjects = "INVENTORY4"
End If
End If
End If
End If
table_object_row.Range("INVENTORY1", 1).Value = ComboBox1.Value
last_row_with_data = the_sheet.Range("A" & Rows.Count).End(xlUp).Row
Sheets("ALL USAGES").Cells(lastrow + 1, "A").Value = TextBox1.text
Sheets("ALL USAGES").Cells(lastrow + 1, "B").Value = TextBox2.text
Sheets("ALL USAGES").Cells(lastrow + 1, "C").Value = TextBox3.text
Sheets("ALL USAGES").Cells(lastrow + 1, "D").Value = TextBox4.text
Sheets("ALL USAGES").Cells(lastrow + 1, "D").Columns.AutoFit
MsgBox ("Data is added successfully")
TextBox1.Value = ""
TextBox2.Value = ""
TextBox3.Value = ""
TextBox4.Value = ""
ComboBox1.Value = ""
Worksheets("DASHBOARD").Activate
Worksheets("DASHBOARD").Cells(1, 1).Select
End Sub
Private Sub UserForm_Initialize()
ComboBox1.Value = SetFocus
TextBox2.text = Date
ComboBox1.List = Array("INVENTORY1", "INVENTORY2", "INVENTORY3", "INVENTORY4")
End Sub