VBA:如何search公式驱动值?
我试图searchdate,我已经在单元格K1 =today()
….
但是,每当我录制macros时,它都将继续使用macros写入的date。 我很好奇的是将剪贴板上的内容粘贴到VBAsearchfunction中的方法。
所以我想在A列中查找K1中的内容。 这是我现在拥有的代码(发现我刚input的内容是为了帮助你了解我在找什么)
Range("K1").Select Selection.Copy Columns("A:A").Select Selection.Find(What:="COPY CONTENTS OF CELL K1", After:=ActiveCell, LookIn:=xlFormulas, _ LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _ MatchCase:=False, SearchFormat:=False).Activate
这应该做到这一点。 请注意,如果未find今天的date,您的原始代码将会引发错误。 通常,在使用Find()时,在尝试使用它之前testing返回值更为安全。
Dim f As Range Set f = Columns("A:A").Find(What:=Date(), After:=ActiveCell, LookIn:=xlFormulas, _ LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _ MatchCase:=False, SearchFormat:=False) If Not f Is Nothing then 'do something with f Else '???? do what End If
你可以用这个replace你的整个代码:
Activesheet.Columns("A:A").Find(What:=ActiveSheet.Range("K1"), After:=ActiveCell, _ LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _ MatchCase:=False, SearchFormat:=False).Activate
发生了什么事情是没有办法粘贴一个单元格的内容通过。复制直接到一个VBA函数。 所以我把你想要粘贴的东西直接放到函数中。
我想你也会发现这有帮助: 如何避免使用selectExcel VBAmacros