
歓迎だけを赤字にするよ
この説明は、ChatGPTで作成しています。
このプロシージャは、Excelのセルにある文字列の中で「歓迎」という文字を見つけ、それを赤色に変更するものです。具体的な動作を以下に説明します。
画面更新の停止: `Application.ScreenUpdating = False` この行は、プロシージャの実行中に画面の更新を停止し、動作を速くするためのものです。
変数の宣言:
`myRng`: 選択された範囲の各セルを指します。
`myStr`: 現在チェックしている文字列の部分を格納します。
`i`: 文字列の位置を追跡するためのインデックスです。
`a`: 今回のプロシージャでは使用されていない変数です。
セル内の文字列をチェック: `For Each myRng In Selection` ここでは、選択された各セルについて処理を行います。
文字列の部分を取得: `For i = 1 To Len(myRng)` これは、セル内の文字を一つずつチェックするためのループです。`Mid(myRng.Value, i, 2)` で、文字列の部分(2文字)を取得します。
「歓迎」を見つける: `If myStr Like "歓迎"` ここで、取得した2文字が「歓迎」であるかどうかをチェックします。
文字の色を変更: `With myRng.Characters(Start:=i, Length:=2).Font` この部分では、「歓迎」という文字のフォント色を赤色(ColorIndex = 3)に設定します。
画面更新の再開: `Application.ScreenUpdating = True` これにより、プロシージャが終了した後に画面の更新が再開されます。
Excel VBA リファレンス | Microsoft Learn: https://learn.microsoft.com/ja-jp/office/vba/api/overview/excel
この記事のYouTube動画はこちら: https://youtu.be/TAy3mAH4NNA
キーワード:
#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:
Stopping Screen Updates: `Application.ScreenUpdating = False` This line stops screen updates during the procedure to speed up the execution.
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.
Checking Strings in Cells: `For Each myRng In Selection` This iterates through each selected cell.
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).
Finding "歓迎": `If myStr Like "歓迎"` This checks if the substring is "歓迎".
Changing Text Color: `With myRng.Characters(Start:=i, Length:=2).Font` This sets the font color of the "歓迎" text to red (ColorIndex = 3).
Resuming Screen Updates: `Application.ScreenUpdating = True` This resumes screen updates after the procedure completes.
Excel VBA Reference | Microsoft Learn: https://learn.microsoft.com/ja-jp/office/vba/api/overview/excel
YouTube video for this article: https://youtu.be/TAy3mAH4NNA
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