Excel VBA Type Mismatch calling Private Sub from ListBox Click

0 votes

A method that will update a specific ListBox (whose listfillrange is a named range with a dynamic size) is attached to a Sheet on which I have an ActiveX List Box. The first sheet of the Microsoft Excel Objects contains all of the following code.

Function to update ListBox

Private Sub update(lst As ListBox)
    lst.ListIndex = -1
    lst.ListFillRange = lst.ListFillRange
End Sub

I want to call this function in two scenarios:

  1. When the Worksheet changes:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Application.Intersect("{some ranges}") Is Nothing Then update Me.ListBox
End Sub
  1. When a different ListBox is clicked on:
Private Sub OtherListBox_Click()
    update Me.ListBox
End Sub

However when the code tries to call the update sub it gives me a Type Mismatch error on the update line This is my first time using List Boxes, so my understanding is pretty limited and I can't understand why both scenarios won't work

Feb 27, 2023 in Others by Kithuzzz
• 38,000 points
745 views

1 answer to this question.

0 votes

Confusion: You must declare the parameter as MSForms if you are using ActiveX controls. Listbox.

Private Sub update(lst As MSForms.ListBox)
    lst.ListIndex = -1
    lst.ListFillRange = lst.ListFillRange 
End Sub

ListBox (without the MSForms.) will refer to the "older" Listbox type (so called Form Controls).

answered Mar 18, 2023 by narikkadan
• 63,600 points

Related Questions In Others

0 votes
1 answer

Runtime error 438 while importing data in excel from secured website using VBA

Replace With ieDoc.forms(0) .userType.Value = "1" ...READ MORE

answered Sep 23, 2022 in Others by narikkadan
• 63,600 points
890 views
0 votes
1 answer

Open SAP from Excel VBA

It just means that there is no ...READ MORE

answered Sep 30, 2022 in Others by narikkadan
• 63,600 points
4,447 views
0 votes
1 answer

Remove formulas from all worksheets in Excel using VBA

Try this : Option Explicit Sub test1() ...READ MORE

answered Oct 3, 2022 in Others by narikkadan
• 63,600 points
2,019 views
0 votes
1 answer
0 votes
1 answer

Type mismatch error when referring to array element by location vba

We utilise MID to parse the string. ...READ MORE

answered Feb 11, 2023 in Others by Kithuzzz
• 38,000 points
753 views
0 votes
1 answer

Retrieve epay.info Balance with VBA and Excel

This code should log you in, provided ...READ MORE

answered Sep 5, 2018 in Blockchain by digger
• 26,740 points
1,211 views
0 votes
1 answer

How to load file to Excel Power query from SFTP site

Currently, I don't think there is a ...READ MORE

answered Dec 3, 2018 in Power BI by Upasana
• 8,620 points
3,662 views
0 votes
1 answer

Using VBA Excel to create a gramatically correct list

The Excel AND function is a logical ...READ MORE

answered Feb 9, 2022 in Others by gaurav
• 23,260 points
907 views
0 votes
1 answer

How Do I Correct a ByRef Mismatch Error in VBA for Worksheet_Change Sub in Excel?

Len of a string returns what you need. ...READ MORE

answered Apr 1, 2023 in Others by narikkadan
• 63,600 points
1,863 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP