我试图在Excel2010/2013中创建一个UserForm,它将查看项目列表,并根据我提供的数字返回一个完整的列表。
下面是这个列表的样子:见示例 (托管在Imgur上的图像)
A这是一段片段以防图像无法载入..。
地点
A2: 0001 \x{e76f} B2:电影1: C2: 32
A3: 0001 \x{e76f} B3:电影2: C3: 18
A4: 0001 \x{e76f} B4:电影3: C4: 10
A5: 0004 \ B5:电影1: C5: 32
A6: 0007 \x{e76f} B6:电影1: C6: 32
A7: 0007 \x{e76f} B7:电影2: C7: 18
A8: 0009 \x{e 010} B8:电影1: C8: 32
A9: 0014 \x{e76f} B9:电影1: C9: 32
我有一个用户表单,它将返回列表中的第一项,但不返回完整的列表。理想情况下,我希望避免使用列表框,主要是因为目标是能够复制完整列表中的项目。
我已经尝试了Index()公式,但是我不知道如何在VBA中转换它。
你得到的任何帮助都会很棒!
发布于 2014-06-19 05:20:07
我已经为您编写了这篇文章,如果您的位置值是在A
列中给出的,那么B
中的标题和C
中的几天后的标题应该可以工作:
Private Sub SUBMITBUTTON_Click()
Dim counter As Integer, TITLELIST(), DAYSPAST(), fullString As String
fullString = ""
If LOCATIONTEXTBOX.Text = "" Then
MsgBox "Please input a location"
Exit Sub
End If
For Each Cell In ActiveSheet.UsedRange.Cells
If Cell.Value = LOCATIONTEXTBOX.Text Then
counter = counter + 1
End If
Next
ReDim TITLELIST(counter)
ReDim DAYSPAST(counter)
counter = 0
For i = 1 To Cells(1, 1).End(xlDown).Row
If Cells(1, i).Value = LOCATIONTEXTBOX.Text Then
TITLELIST(counter) = Cells(i, 2).Value
DAYSPAST(counter) = Cells(i, 3).Value
fullString = fullString & CStr(TITLELIST(counter)) & "," & CStr(DAYSPAST(counter)) & ","
counter = counter + 1
End If
Next
MsgBox fullString
Range("H8").Value = fullString
End Sub
如果您更改了SUBMITBUTTON和LOCATIONTEXTBOX的名称,那么它应该在您的userform中工作。
https://stackoverflow.com/questions/24276035
复制相似问题