1
我有一个列表框,我正在阅读一个文本文件,其中有几行。我现在点击一行来搜索表单中单击的值,然后将该值添加到列表框的底部。Excel VBA添加下列项目列表框选择
如果我在我的列表框中有10行,并且我点击了第5行,那么如何向第6行添加项目?
Sub FindListValue()
Dim FirstAddress As String
Dim rSearch As Range 'range to search
Dim c As Range
Sheets("PN-BINS").Activate
Set rSearch = ActiveSheet.Range("b1", Range("b65536").End(xlUp))
strFind = Me.ListBox1.Value 'what to look for
With rSearch
Set c = .Find(strFind, LookIn:=xlValues, LookAt:=xlWhole)
If Not c Is Nothing Then 'found it
c.Select
'MsgBox strFind & c.Offset(0, -1).Value
Me.ListBox1.AddItem strFind & " " & c.Offset(0, -1).Value
Else: MsgBox strFind & " is not listed!" 'search failed
'Range("K1").Select
End If
End With
End Sub
请发表您的当前VBA代码列表框。 – Ralph