見出し画像

歓迎だけを赤字にするよ

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

このプロシージャは、Excelのセルにある文字列の中で「歓迎」という文字を見つけ、それを赤色に変更するものです。具体的な動作を以下に説明します。

  1. 画面更新の停止: `Application.ScreenUpdating = False` この行は、プロシージャの実行中に画面の更新を停止し、動作を速くするためのものです。

  2. 変数の宣言:

    • `myRng`: 選択された範囲の各セルを指します。

    • `myStr`: 現在チェックしている文字列の部分を格納します。

    • `i`: 文字列の位置を追跡するためのインデックスです。

    • `a`: 今回のプロシージャでは使用されていない変数です。

  3. セル内の文字列をチェック: `For Each myRng In Selection` ここでは、選択された各セルについて処理を行います。

  4. 文字列の部分を取得: `For i = 1 To Len(myRng)` これは、セル内の文字を一つずつチェックするためのループです。`Mid(myRng.Value, i, 2)` で、文字列の部分(2文字)を取得します。

  5. 「歓迎」を見つける: `If myStr Like "歓迎"` ここで、取得した2文字が「歓迎」であるかどうかをチェックします。

  6. 文字の色を変更: `With myRng.Characters(Start:=i, Length:=2).Font` この部分では、「歓迎」という文字のフォント色を赤色(ColorIndex = 3)に設定します。

  7. 画面更新の再開: `Application.ScreenUpdating = True` これにより、プロシージャが終了した後に画面の更新が再開されます。



キーワード:
#excel #できること #vba #赤字 #歓迎 #文字列操作 #セル操作 #色変更 #文字色 #エクセルマクロ #プロシージャ #プログラミング初心者 #フォント設定 #条件付きフォーマット #選択範囲 #変数 #画面更新 #コード解説 #文字列チェック #エクセル操作


WelcomeColorChange

This explanation is created with ChatGPT.

This procedure finds the string "歓迎" (welcome) in the selected cells in Excel and changes its color to red. Here is a step-by-step explanation of its operation:

  1. Stopping Screen Updates: `Application.ScreenUpdating = False` This line stops screen updates during the procedure to speed up the execution.

  2. Variable Declaration:

    • `myRng`: Refers to each cell in the selected range.

    • `myStr`: Stores the substring currently being checked.

    • `i`: An index to keep track of the position in the string.

    • `a`: A variable that is not used in this procedure.

  3. Checking Strings in Cells: `For Each myRng In Selection` This iterates through each selected cell.

  4. Getting Substrings: `For i = 1 To Len(myRng)` This loop checks each character in the cell. `Mid(myRng.Value, i, 2)` gets a substring (2 characters).

  5. Finding "歓迎": `If myStr Like "歓迎"` This checks if the substring is "歓迎".

  6. Changing Text Color: `With myRng.Characters(Start:=i, Length:=2).Font` This sets the font color of the "歓迎" text to red (ColorIndex = 3).

  7. Resuming Screen Updates: `Application.ScreenUpdating = True` This resumes screen updates after the procedure completes.



Keywords:
#excel #can_do #vba #red_text #welcome #string_manipulation #cell_operations #color_change #text_color #excel_macro #procedure #beginner_programming #font_settings #conditional_formatting #selected_range #variables #screen_update #code_explanation #string_check #excel_operations

いいなと思ったら応援しよう!