トップ 差分 一覧 ping ソース 検索 ヘルプ PDF RSS ログイン

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



目次



記事一覧

キーワード

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 



YAGI Hiroto (piroto@a-net.email.ne.jp)
twitter http://twitter.com/pppiroto

Copyright© 矢木 浩人 All Rights Reserved.