【发布时间】:2014-05-27 20:31:48
【问题描述】:
如何在列表框中找到所选项目的行号?
现在我有一个 sub 将所有找到的项目输入到列表框中,见下文
Sub findnext()
Dim Name As String
Dim f As Range
Dim ws As Worksheet
Dim s As Integer
Dim findnext As Range
Set ws = ThisWorkbook.Worksheets("Master")
Name = surname.Value
ListBox1.Clear
Set f = Range("A:A").Find(what:=Name, LookIn:=xlValues)
Set findnext = f
Do
Debug.Print findnext.Address
Set findnext = Range("A:A").findnext(findnext)
ListBox1.AddItem findnext.Value
ListBox1.List(ListBox1.ListCount - 1, 1) = ws.Cells(findnext.Row, xFirstName).Value
ListBox1.List(ListBox1.ListCount - 1, 2) = ws.Cells(findnext.Row, xTitle).Value
ListBox1.List(ListBox1.ListCount - 1, 3) = ws.Cells(findnext.Row, xProgramAreas).Value
ListBox1.List(ListBox1.ListCount - 1, 4) = ws.Cells(findnext.Row, xEmail).Value
ListBox1.List(ListBox1.ListCount - 1, 5) = ws.Cells(findnext.Row, xStakeholder).Value
ListBox1.List(ListBox1.ListCount - 1, 6) = ws.Cells(findnext.Row, xofficephone).Value
ListBox1.List(ListBox1.ListCount - 1, 7) = ws.Cells(findnext.Row, xcellphone).Value
'ListBox1.List(ListBox1.ListCount - 1, 8) = ws.Cells(findnext.Row, xFirstName).Value
Loop While findnext.Address <> f.Address
End Sub
如果用户选择列表框中的项目,那么它会将信息填充到用户窗体的文本框中
Sub ListBox1_Click()
surname.Value = ListBox1.List(ListBox1.ListIndex, 0)
firstname.Value = ListBox1.List(ListBox1.ListIndex, 1)
tod.Value = ListBox1.List(ListBox1.ListIndex, 2)
program.Value = ListBox1.List(ListBox1.ListIndex, 3)
email.Value = ListBox1.List(ListBox1.ListIndex, 4)
SetCheckBoxes ListBox1.List(ListBox1.ListIndex, 5) '<<<< added
officenumber.Value = ListBox1.List(ListBox1.ListIndex, 6)
cellnumber.Value = ListBox1.List(ListBox1.ListIndex, 7)
End Sub
我想从ListBox1_click() 中弄清楚如何确定列表框中所选项目的行号。一旦我弄清楚这一点,我将编写一个 update sub 代码,它将定位所选项目的行号,我将在文本框中重新输入信息并更新该行的信息。
当我做find.. 时,我考虑在隐藏的工作表中存储一行#。但我不知道如何将found 的行# 与listbox 中选择的内容联系起来
希望...这是有道理的,如果不是请告诉我!
【问题讨论】: