这是一个简单的例程,我用来在电子表格表格中查找某些内容并将结果发布在同一页面上(很容易更改为发布在另一张工作表上)。希望这有助于或引导您朝着正确的方向前进。(粗鲁但有效)
Private Sub CommandButton3_Click()
'FIND A VALUE IN THE LIST AND POST RESULTS
Dim myName, myNumber, myComp
'Clear the results area
With Worksheets("SheetName").Range("H2:J30").ClearContents
End With
x = 2 'The row to start posting results to
y = 0
'This is the range to search
With Worksheets("SheetName").Range("A1:D300")
Set found = .Find(What:=y, LookIn:=xlValues, LookAt:=xlWhole)
If Not found Is Nothing Then
firstAddress = found.Address
Do
Set ws = Sheets("SheetName")
myName = ws.Range("A" & found.Row).Value 'Value in column A
myNumber = ws.Range("B" & found.Row).Value 'Value in column B
myComp = ws.Range("C" & found.Row).Value 'Value in column C
'I use a MsgBox at first for testing, then comment it out when I know it's working
'MsgBox myName & " " & myNumber & " " & myComp
'Post the results to the desired area
ws.Range("H" & x).Value = myName
ws.Range("I" & x).Value = myNumber
ws.Range("J" & x).Value = myComp
x = x + 1
Set found = .FindNext(found)
If found Is Nothing Then
GoTo DoneFinding
End If
Loop While Not found Is Nothing And found.Address <> firstAddress
End If
DoneFinding:
End With
Range("A2").Select
End Sub