2013-12-23 27 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