2

レコード機能を使用して、このマクロ コードを作成しました。

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 列にわたってタブ移動し、指定された単語に貼り付けます。

列の先頭から開始しないと見つからなくなるまで、同じ列で指定された単語を検索し続けます。

それが理にかなっていることを願っています。

4

2 に答える 2

0

よくわかりませんが、あなたが探しているものは次のとおりです。

For each cell in columns(4).cells
    If cell.value="Text to find" Then Cell.offset(0,1) = "Text to enter"
Next cell
于 2013-06-21T03:42:04.780 に答える
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
于 2013-06-21T13:02:40.407 に答える