【发布时间】:2017-03-21 20:29:03
【问题描述】:
目标:创建一个用户表单并接受用户输入,然后从用户输入中将其放入一个列表中,当您单击该列表时,它会自动在整个工作簿中找到它。
类似这样的:
我看到了这个帖子:Match in whole workbook
我从中创造了一些东西:
Public Sub CommandButton3_Click()
Dim TempArray As Variant
Dim RealArray()
TempArray = Application.InputBox("Select a range", "Obtain Range Object", Type:=64)
ArrayRows = UBound(TempArray)
ReDim RealArray(1 To ArrayRows)
For i = 1 To ArrayRows
RealArray(i) = TempArray(i, 1)
Next i
MsgBox "The number if rows selected are " & ArrayRows
ListBox1.List = RealArray
ListBox1 Arraay:=RealArray
End Sub
Public Sub ListBox1_Click(ByRef Arraay() As Variant)
Dim Sh As Worksheet
Dim something As Range
Dim ArrayRows As Long
For Each Sh In ThisWorkbook.Worksheets
With Sh.UsedRange
For i = 1 To ArrayRows
Set something = RealArray.Find(What:=RealArray(i))
If Not something Is Nothing Then
Do Until something Is Nothing
test = something.Value
Set something = .FindNext(something)
Loop
End If
Next i
End With
Set something = Nothing
Next
End Sub
创建后,我收到关于第二个子的错误。
过程声明与同名事件或过程的描述不匹配
【问题讨论】:
-
Public Sub ListBox1_Click(ByRef Arraay() As Variant)不带任何参数。应该是ListBox1_Click() -
@SiddharthRout 但是如何在 sub 之间传递数组?这不是方法之一吗?抱歉,我对 VBA 很陌生