2013-06-20 15 views
2

我已經創建了這個宏代碼使用記錄功能。創建重複的Excel宏代碼,直到沒有更多的文字提到

Sub Macro1() 
    Cells.Find(What:="Text to find", After:=ActiveCell, LookIn:=xlFormulas, _ 
     LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _ 
     MatchCase:=True, SearchFormat:=False).Activate 
    Range("E5").Select 
    ActiveCell.FormulaR1C1 = "text to enter" 
    Range("D6").Select 
    Cells.Find(What:="Text to find", After:=ActiveCell, LookIn:=xlFormulas, _ 
     LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _ 
     MatchCase:=True, SearchFormat:=False).Activate 
    Range("E9").Select 
    ActiveCell.FormulaR1C1 = "text to enter"  
End Sub 

我需要這個宏繼續通過同一列,直到它無法找到搜索詞中的任意多個實例,沒有它要回柱的頂部。

因此,它從一列開始,每次找到指定的單詞時,它會跨1列進行標記並粘貼到指定的單詞中。

它繼續在同一列中搜索指定的單詞,直到它無法從列的頂部開始找到它。

希望有一定道理。

回答

0

不知道我理解,但我覺得你想找的是:

For each cell in columns(4).cells 
    If cell.value="Text to find" Then Cell.offset(0,1) = "Text to enter" 
Next cell 
0

您可以使用FindFindNext迅速做到這一點,即:文本

  • 搜索欄d在StrOld
  • 在列E中輸入任何匹配文字StrIn

代碼

Sub Recut() 
Dim strAddress As String 
Dim StrIn As String 
Dim StrOut As String 
Dim rng1 As Range 
StrOld = "Old" 
StrIn = "New" 

Set rng1 = Range("D:D").Find(StrOld, , xlFormulas, xlWhole, , , True) 

If Not rng1 Is Nothing Then 
     strAddress = rng1.Address 
     Do 
      rng1.Offset(0, 1) = StrIn 
      Set rng1 = Range("D:D").FindNext(rng1) 
     Loop While Not rng1 Is Nothing And rng1.Address <> strAddress 
End If 
End Sub 
相關問題