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