[英]VBA Copy Paste formula search
下面的代碼取自先前的問題
我的問題-如果查找和搜索值是公式,如何使它起作用? ..我嘗試更改.Value2,但似乎不起作用。
With Sheets("SheetName") ' Change to your actual sheet name
Dim r As Range: Set r = .Range("C10:G10").Find(.Range("A10").Value2, , , xlWhole)
If Not r Is Nothing Then r.Offset(4, 0).Resize(5).Value2 = .Range("A14:A18").Value2
結束於
如果要查找公式的結果,則需要為LookIn參數指定xlValues
。 如果為空,則默認為xlFormulas
。 例如,要查找在工作表“ foo”上產生“ Bar”的任何公式(即=CONCATENATE("B","a","r")
),您可以這樣做:
With ActiveWorkbook.Sheets("Foo")
Dim r As Range
Set r = .UsedRange.Find("Bar", , xlValues, xlWhole)
If Not r Is Nothing Then
Debug.Print r.Address
End If
End With
如果要查找包含實際公式的工作表,則可以完全省略LookIn參數,也可以顯式指定它:
With ActiveWorkbook.Sheets("Foo")
Dim r As Range
Set r = .UsedRange.Find("=CONCATENATE(""B"",""a"",""r"")", , _
xlFormulas, xlWhole)
If Not r Is Nothing Then
Debug.Print r.Address
End If
End With
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.