我必須找到一個值celda在一個Excel工作表。我使用這個VBA代碼找到它:如何找到由VBA代碼的Excel列的值Cells.Find
Set cell = Cells.Find(What:=celda, After:=ActiveCell, LookIn:= _
xlFormulas, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:= _
xlNext, MatchCase:=False, SearchFormat:=False)
If cell Is Nothing Then
'do it something
Else
'do it another thing
End If
問題是,當我只有一個Excel列找到該值。我用下面的代碼找到它:
Columns("B:B").Select
Selection.Find(What:="VA22GU1", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
但我不知道如何使其適應第一VBA代碼,因爲我使用的值nothing
。
http://www.siddharthrout.com/2011/07/14/find-and-findnext-in-excel-vba/也請避免使用'.Select'請參閱此鏈接HTTP: //stackoverflow.com/questions/10714251/excel-macro-avoiding-using-select/10718179#10718179 – 2013-02-18 08:07:05
如果你只是想知道,如果該值範圍內的某處存在,它是更快的執行(值得的,如果檢查數百值)使用Excel公式。如果celda例如是一個數字,您可以使用IF評估( 「COUNTIF(工作表Sheet1!A1:A1000,」 &celda& 「)」)> 0 THEN ... – lessthanideal 2013-11-06 14:32:09