[英]VBA Copy Paste formula search
Code below taken from a previous question asked 下面的代码取自先前的问题
My Question - How do i get this to work if the find and search values are formulas? 我的问题-如果查找和搜索值是公式,如何使它起作用? ..I've tried changing the .Value2 but doesn't seem to work. ..我尝试更改.Value2,但似乎不起作用。
VBA Copy Paste string search VBA复制粘贴字符串搜索
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
End With 结束于
If you're looking for the results of formulas, you need to specify xlValues
for the LookIn parameter. 如果要查找公式的结果,则需要为LookIn参数指定xlValues
。 When it's blank it defaults to xlFormulas
. 如果为空,则默认为xlFormulas
。 For example, to find any formula that results in "Bar" (ie =CONCATENATE("B","a","r")
) on Sheet "foo", you would do this: 例如,要查找在工作表“ 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
If you want to find a sheet that contains the actual formula you can either leave out the LookIn parameter entirely or explicitly specify it: 如果要查找包含实际公式的工作表,则可以完全省略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.