對于這兩個 lignes,我沒有得到相同的結果。有人可以解釋我嗎?
Dim mnt As String
Dim I As Integer
Ligne = 3
'Case 1: Working
mnt = Cells(WorksheetFunction.Match(r.Offset(, -4), Sheets(7).Range("I3:I200"), 0) 2, 9).Address
'Case 2: Not working
mnt = Cells(WorksheetFunction.Match(r.Offset(, -4), Sheets(7).Range("I" & Ligne & ":I200"), 0) 2, 9).Address
但是如果我Range("I" & Ligne & ":I200").select正確選擇范圍 I3:I200
在第 2 種情況下,沒有錯誤訊息,它只是接縫總是回傳 I3 的值,而不是在 I3:I200 中搜索。
有人能解釋一下為什么它在第二種情況下不起作用嗎?
謝謝你
uj5u.com熱心網友回復:
針對您的評論,我建議切換方法以使用Range.Find和.FindNext。這兩種方法可以快速搜索作業表中的字串值并回傳其位置。FindNext 方法允許您重復搜索,查找具有相同字串值的其他單元格。
這是一個如何制作.Find和.FindNext回圈的簡單示例。
Sub Example()
'Find all instances of "Steve" on the activesheet and highlight them
Call Highlight("Steve")
End Sub
Sub Highlight(FindText As String, Optional WithinSheet As Worksheet)
If WithinSheet Is Nothing Then Set WithinSheet = ActiveSheet
Dim rFirst As Range
Set rFirst = WithinSheet.Cells.Find(What:=FindText, LookIn:=xlValues, LookAt:=xlWhole, MatchCase:=False)
Dim rNext As Range
Set rNext = rFirst
Do
Set rNext = WithinSheet.Cells.FindNext(After:=rNext)
rNext.Interior.Color = 65535
Loop While Not rNext.Address = rFirst.Address
End Sub
要使用這個想法創建您自己的子,您可以用rNext.Interior.Color = 65535您希望對在此回圈中找到的每個單元格執行的任何其他操作替換該行。例如,您可以rNext.Offset(0,1) = "Here!"在每個找到的單元格旁邊插入一些文本。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/324387.html
