我試圖讓它能夠找到「燈光」的第二個結果,以防萬一出現此術語的各種情況。下面的代碼找到所考慮範圍內的第一個事件。使用VBA選擇「查找」的第二個結果
Dim ws As Worksheet
Dim rng1 As Range
Dim y As Range
Columns("B:B").Select
Selection.Find(What:="1", After:=ActiveCell, LookIn:=xlValues, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Select
Set x = Range(Selection, Selection.End(xlDown)).Offset(0, 3)
Range(x.Address(0, 0)).Select
Selection.Find(What:="Lights", After:=ActiveCell, LookIn:=xlValues, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Activate
Selection.FindNext(After:=ActiveCell).Activate
Selection.FindNext(After:=ActiveCell).Select
你的代碼有點混亂。你能解釋一下你打算做什麼嗎?首先搜索「1」,然後搜索「Lights」(在發現「1」的範圍內)。用簡單的語言說出你想要做什麼。 – varocarbas
該代碼在列b中找到「1」,然後將活動單元移動到列b中包含1的行的列e,然後選擇一個範圍,直到被佔用單元的末尾......它的最後部分開始與光找到是關鍵部分。我希望它能找到第n個(即第二個或第三個) –
你的問題很清楚,我問過要確保上面的代碼正在做你想做的事情,請馬上寫下我的答案 – varocarbas