首页 > 解决方案 > Excel VBA列表框多选填充其他列表框 - 多页的VBA代码给出错误

问题描述

我正在使用此处的视频教程创建一个 Excel VBA 列表框多选来填充其他列表框:

https://www.youtube.com/watch?v=dWTEUWqlQAc

基本上,这意味着,“Excel,如果我从 ListBox 1 中选择这些项目,从 Excel Column C 获取一系列值,则返回我在同一行的 Excel Column A 的值列表”

但是,我不断收到错误消息“编译错误无效使用属性”

这在此处突出显示了此代码:

Private Sub ListBox1_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)

我不确定我做错了什么。是因为我正在使用多页或带有此代码的东西吗?

我曾尝试重新观看该该死的教程,但似乎没有任何效果。

Private Sub ListBox1_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)


'find lastrow

lastrow = ThisWorkbook.Worksheets("List of Emails").Cells(Rows.Count, 1).End(xlUp).Row


'clear listbox1
Me.ListBox2.Value

'not just one value, but whichever were selected
For SelItm = LBound(Me.ListBox1.Email) To UBound(Me.ListBox1.Email)
    If Me.ListBox1.Selected(SelItm) = True Then
       'It is selected

        curVal = Me.ListBox1.List(SelItm, 0)

        For X = 2 To lastrow
            If emails.Cells(X, "c") = curVal Then
                'found a match; populate listbox2
                Me.ListBox2.AddItem ThisWorkbook.Worksheets("List of Emails").Cells(X, "a")
            End If
        Next X


    End If


Next SelItm


End Sub

无论我多么努力,我都无法摆脱错误消息。像 wtf 是“编译错误无效使用属性”?我完全按照 Youtube 指南所做的。

感谢是否有人可以提供任何形式的帮助。谢谢!

标签: vba

解决方案


推荐阅读