見出し画像

文章の末尾に済みと赤字で追加するよ

この説明は、ChatGPTで作成しています。

このVBAプロシージャは、選択されたセルの内容の末尾に「済み」という文字を追加し、その「済み」の文字を赤色にするものです。

手順

  1. Application.ScreenUpdating = False
    画面の更新を停止して、処理速度を上げます。

  2. On Error Resume Next
    エラーが発生しても無視して次の行に進みます。

  3. Dim myRng As Range
    Dim myStr As String
    Dim i As Long
    変数を宣言します。`myRng`はセル範囲、`myStr`は文字列、`i`はループカウンターです。

  4. For Each myRng In Selection
    選択されたセル範囲の各セルについてループを開始します。

  5. myRng = myRng.Value & "_済み"
    各セルの内容の末尾に「済み」を追加します。

  6. For i = 1 To Len(myRng)
    セルの内容の文字数だけループをします。

  7. myStr = Mid(myRng.Value, i, 3)
    文字列の中から3文字を取得します。

  8. If myStr Like "_済み" Then
    取得した3文字が「_済み」と一致するか確認します。

  9. With myRng.Characters(Start:=i, Length:=3).Font
    一致した場合、その文字のフォント色を赤色(ColorIndex = 3)に変更します。

  10. Next i
    内部ループを終了し、次の文字に移ります。

  11. Next myRng
    外部ループを終了し、次のセルに移ります。

  12. Application.ScreenUpdating = True
    最後に画面の更新を再開します。

このプロシージャを実行すると、選択したセルの内容に「済み」が追加され、その部分が赤色で表示されます。

Excel VBA リファレンス | Microsoft Learn

この記事のYouTube動画はこちら


Add "済み" in Red Text to the End of Each Selected Cell

This explanation is created by ChatGPT.

This VBA procedure adds the characters "済み" to the end of the content of each selected cell and changes the text color of "済み" to red.

Steps:

  1. Application.ScreenUpdating = False
    Stops screen updating to speed up the process.

  2. On Error Resume Next
    Ignores any errors and continues with the next line.

  3. Dim myRng As Range
    Dim myStr As String
    Dim i As Long
    Declares variables. `myRng` is for cell range, `myStr` is for string, and `i` is for loop counter.

  4. For Each myRng In Selection
    Starts a loop for each cell in the selected range.

  5. myRng = myRng.Value & "_済み"
    Adds "済み" to the end of the content of each cell.

  6. For i = 1 To Len(myRng)
    Loops through each character in the cell content.

  7. myStr = Mid(myRng.Value, i, 3)
    Extracts 3 characters from the string.

  8. If myStr Like "_済み" Then
    Checks if the extracted 3 characters match "_済み".

  9. With myRng.Characters(Start:=i, Length:=3).Font
    If matched, changes the font color of these characters to red (ColorIndex = 3).

  10. Next i
    Ends the inner loop and moves to the next character.

  11. Next myRng
    Ends the outer loop and moves to the next cell.

  12. Application.ScreenUpdating = True
    Finally, resumes screen updating.

When this procedure is executed, "済み" will be added to the end of the content of the selected cells, and this text will be displayed in red.

Excel VBA Reference | Microsoft Learn

YouTube video of this article here


ハッシュタグ
#excel #できること #vba #セル操作 #自動化 #書式設定 #文字色変更 #エクセルVBA #初心者向け #プログラミング #効率化 #コード解説 #エクセル #マクロ #条件付き書式 #テキスト操作 #ループ処理 #エラーハンドリング #選択範囲 #セル範囲

この記事が気に入ったらサポートをしてみませんか?