1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

セル中の特定の文字のプロパティを設定するマクロ

Last updated at Posted at 2017-06-01
  • セル中の特定の文字を強調したい時に
  • セルを選択して実行する想定ですが、必要に応じて変更してください
set_char_properties
Const SEARCH_CHAR As String = "|" ' 検索文字(列)

Sub set_char_properties()
    Dim char_len As Long
    char_len = Len(SEARCH_CHAR)
    
    For Each r In Selection ' 選択セルを順次処理
        Dim start_idx As Long
        Dim target_char_idx As Long
        start_idx = 1
        
        Do
            target_char_idx = InStr(start_idx, r.Value, SEARCH_CHAR)
            If (target_char_idx = 0) Then Exit Do ' 対象文字がなければ次のセルへ
            
            r.Characters(target_char_idx, char_len).Font.ColorIndex = 3 ' 赤字
            r.Characters(target_char_idx, char_len).Font.Bold = True ' 太字
            
            ' 検索開始位置を更新
            start_idx = target_char_idx + char_len
        Loop
        
    Next r
End Sub

参考文献

森本家のワークシート 特定キーワードを目立たせろ

1
0
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?