| ページ一覧 | ブログ | twitter |  書式 | 書式(表) |

MyMemoWiki

Excel VBA すべてのシートに対して一括置換

提供: MyMemoWiki
2020年2月16日 (日) 04:25時点におけるPiroto (トーク | 投稿記録)による版
(差分) ← 古い版 | 最新版 (差分) | 新しい版 → (差分)
ナビゲーションに移動 検索に移動

Excel VBA すべてのシートに対して一括置換

Excel | Excel VBA |

すべてのシートに対して一括置換する

Sub AllReplace()
    
    Dim f       As String
    Dim t       As String
    Dim i       As Integer
    Dim sht     As Excel.Worksheet
    
    f = InputBox("置換対象文字列を入力してください")
    
    If Trim$(f) <> "" Then
        t = InputBox("置換後文字列を入力してください")
    End If

    If Trim$(t) = "" Then
        Exit Sub
    End If
    
    For i = 1 To ActiveWorkbook.Sheets.Count
        Set sht = ActiveWorkbook.Sheets(i)
        
        If sht.Name = f Then
            sht.Name = t
        End If

        sht.Cells.Replace What:=f, Replacement:=t, LookAt:= _
        xlPart, SearchOrder:=xlByRows, MatchCase:=False, MatchByte:=False
    Next

    Call MsgBox("完了")
End Sub