开发者

Excel 2003 ListBox Type Mismatch when calling a sub

开发者 https://www.devze.com 2023-04-06 10:13 出处:网络
Here\'s a Sub at the Workbook level: Public Sub BuildList(targetSheet As Worksheet, ByRef targetListBox As ListBox, lastRow As Integer)

Here's a Sub at the Workbook level:

Public Sub BuildList(targetSheet As Worksheet, ByRef targetListBox As ListBox, lastRow As Integer)

    For r = 1 To lastRow

        If Trim(targetSheet.Range("A" & r).Value) <> "" Then

            With targetListBox

                .AddItem Trim(targetSheet.Range("A" & r).Value)
                .List(.ListCount - 1, 1) = Trim(targetSheet.Range("B" & r))

            End With

        End If

    Next r


End Sub

Here's some code in a Userform that calls it:

Priva开发者_如何学运维te Sub UserForm_Initialize()

    Dim ws As Worksheet
    Dim bottomRow As Integer

    Set ws = Worksheets("Our Status Code")
    bottomRow = ws.Range("A65536").End(xlUp).Row

    ThisWorkbook.BuildList ws, StatusCodesListbox, bottomRow


End Sub

When it hits the line that calls BuildList it throws an error 13 and I can't see why.


You need

 ByRef targetListBox As MSForms.ListBox

There are two types of listbox for Excel.

0

精彩评论

暂无评论...
验证码 换一张
取 消