如何使用Excel Macro VBA在Excel工作表中查找一行?
我现在的代码是:
Set RecT = gConnect.Execute("SELECT [Volume] FROM [Output$] WHERE ((([Facilities])=""IDK"") AND (([Detail_1])=""BPL"" Or ([Detail_1])=""SI"")) ORDER BY [Detail_1];") Worksheets("Results").Cells(52, 4).CopyFromRecordset RecT
首先,使用Set Rect
我在另一个工作表中查找我想要的值,然后将其复制到工作表“结果”(图片中的第52行)的第52行的第4列中。 但是,不要给它确切的指标,我希望它find那个细胞。 正如你在照片中看到的,我必须find列A = traitement,列B = IDK和列C = BPL的行。
我Cells.Find
了一下,发现我必须使用Cells.Find
,但我不明白该怎么做!
像这样的事情应该做的伎俩:
Dim v As Variant Dim i As Long Dim compteur As Long Dim lineFound As Boolean 'Load range contents to array v = Range("A1:C7").Value 'Or wherever your data is 'Iterate through array until desired content found For i = 1 To UBound(v, 1) If v(i, 1) = "traitement" And v(i, 2) = "IDK" And v(i, 3) = "BPL" Then compteur = i lineFound = True Exit For End If Next i 'Report If lineFound Then MsgBox "The thing you want is on line " & compteur Else MsgBox "Didn't find the thing you want." End If