2013-12-23 26 views
1

我有以下代码,并且在想知道如何使搜索结果更具动态性时,即在搜索“价格”之后卡住了,我需要复制“价格”和单元格右边的单元格A1,任何帮助表示赞赏。需要在vba中使用搜索功能时更加动态

Sub Macro1() 
    Cells.Find(What:="price", After:=ActiveCell, LookIn:=xlFormulas, LookAt _ 
     :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _ 
    False, SearchFormat:=False).Activate 
    Range("L14:M14").Select 
    Selection.Copy 
    Range("A1").Select 
    ActiveSheet.Paste 
    Range("A1").Select 
End Sub 

回答

1
Sub Macro1() 
    Dim f as Range 
    Set f = Activesheet.Cells.Find(What:="price", After:=ActiveCell, _ 
       LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, _ 
       SearchDirection:=xlNext, MatchCase:= False, SearchFormat:=False 
    if not f is nothing then 
     f.resize(1,2).copy Activesheet.Range("a1") 
    end if 
End Sub 
+0

它的工作原理,谢谢 – user3045580