0

What I'm looking to accomplish is to have a selection from a listbox (SelectHousingList) filter through a table in excel and come back with values in the same row but different column (much like the index/vlookup). Then display a list of choices with the same value in the first row and show the values in the second listbox (CatalystTypeList).

My code so far is as follows but nothing is showing up in the second listbox. I'm getting no error messages.

The first listbox has 9 values in the rows so I'm trying to use the listindex function in vb to lookup that value in the table in excel.

CatalystTypeList.Clear

lastrow1 = Sheet3.Cells(Rows.Count, 28).End(xlUp).Row

curVal = SelectHousingList.List(SelectHousingList.ListIndex, 6)

Dim dict2 As Object
Set dict2 = CreateObject("Scripting.Dictionary")
For x = 29 To lastrow1
If Worksheets("Catalyst 2020A1").Cells(x, "D") = curVal Then
    If Not dict.Exists(Worksheets("Catalyst 2020A1").Cells(x, "A").Value) Then
        Me.CatalystTypeList.AddItem Worksheets("Catalyst 2020A1").Cells(x, "A")
        dict(Worksheets("Catalyst 2020A1").Cells(x, "A").Value) = 1
    End If
End If
Next x
8
  • Have you tried stepping through the code? That may show the issue. Commented Mar 17, 2020 at 13:29
  • I tried to but I'm struggling to get the step through all the way to this point since I have a lot of code before this. I begin but it ends up not making it to the private sub this is in. Commented Mar 17, 2020 at 13:35
  • 2
    Set a break point in this sub instead of trying to step into it. If you still don't get here, then this code likely isn't the issue. Commented Mar 17, 2020 at 13:40
  • Thank you for that, I was able to step through this code and it is continuously jumping from the if worksheets to the End If without going through the middle so I'll take a look there. Commented Mar 17, 2020 at 13:44
  • 1
    Is curVal correct. Maybe add .value to the checking range. Commented Mar 17, 2020 at 14:05

1 Answer 1

1

I figured out with the help of all the comments how to use break points to help with stepping through and easier for finding errors in my code.

Here's the code I have in the end (I left the lines I took out as comments so everyone could see what I changed).

CatalystTypeList.Clear

lastrow1 = Worksheets("Catalyst 2020A1").Cells(Rows.Count, 28).End(xlUp).Row

curVal = Worksheets("Catalyst 2020A1").Range("D26").Value   
'SelectHousingList.List(SelectHousingList.ListIndex, 6)

Dim dict2 As Object
Set dict2 = CreateObject("Scripting.Dictionary")
For x = 29 To lastrow1
If Worksheets("Catalyst 2020A1").Cells(x, "D") = curVal Then
    'If Not dict.Exists(Worksheets("Catalyst 2020A1").Cells(x, "A").Value) Then
        Me.CatalystTypeList.AddItem Worksheets("Catalyst 2020A1").Cells(x, "A")
        'dict(Worksheets("Catalyst 2020A1").Cells(x, "A").Value) = 1
    End If
'End If
Next x
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.