I have the following code to populate two comboboxes based on one other combobox. before it worked perfectly with normal ranges. Now as I modified it to work with tables it does not work anymore. As the code says, the destination comboboxes are column 2 of two tables and column one of the two tables have similar values which is actually the reference combobox.
Private Sub SPL2loadcombos()
Dim sh As Worksheet
Dim Ir As Long
Dim Ir2 As Long
Dim nameColumn As Range
Dim namecolumn2 As Range
Dim gradescolumnweld As Range
Dim gradesColumn As Range
Dim selectedName As String
Dim i As Long
Dim j As Long
Dim value As String
Dim combo_spl2load As ComboBox
Set sh = ThisWorkbook.Sheets("pl2_steel")
Ir = sh.Cells(Rows.Count, 1).End(xlUp).End(xlUp).Row
Ir2 = sh.Cells(Rows.Count, 7).End(xlUp).End(xlUp).Row
Set nameColumn = sh.ListObjects("tbl_spl2elements").ListColumns(1).DataBodyRange
Set namecolumn2 = sh.ListObjects("tbl_spl2weldings").ListColumns(1).DataBodyRange
Set gradesColumn = sh.ListObjects("tbl_spl2elements").ListColumns(2).DataBodyRange
Set gradescolumnweld = sh.ListObjects("tbl_spl2weldings").ListColumns(2).DataBodyRange
selectedName = Me.combo_spl2load.value
Combo_spl2elementload.Clear
Combo_spl2weldload.Clear
For i = 8 To Ir
If nameColumn.Cells(i).value = selectedName Then
Me.Combo_spl2elementload.AddItem gradesColumn.Cells(i).value
End If
Next i
For i = 8 To Ir2
If namecolumn2.Cells(j).value = selectedName Then
Me.Combo_spl2weldload.AddItem gradescolumnweld.Cells(j).value
End If
Next i
End Sub
As my problem is still not solved even with the corrections from the comments, I am uploading here a screenshot from my worksheet: