LoginSignup
4
4

More than 5 years have passed since last update.

選択したセルの特定文字列を赤くするマクロ

Last updated at Posted at 2015-05-29
Sub 選択範囲の指定の文字を赤く()
    Dim Target As String
    Dim Rng As Object

    '' 赤くしたい文字をユーザーに入力してもらう
    Target = Application.InputBox("変更する文字を入力")

    '' 何も入力されなければ終了する
    If Target = "" Then
        Exit Sub
    End If

    '' 選択したセルをすべて処理する
    For Each Rng In Selection
        Dim Pos As Long

        '' セルに含まれる文字を全て処理する
        Pos = InStr(1, Rng.Value, Target)
        Do Until Pos = 0

            '' 部分的に色を3(赤)に設定
            Rng.Characters(Pos, Len(Target)).Font.ColorIndex = 3

            Pos = InStr(Pos + Len(Target), Rng, Target)
        Loop
    Next

End Sub
4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4