見出し画像

地下鉄という漢字があったらそれだけ赤色にするよ

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

このプロシージャは、Excelのセルの中にある「地下鉄」という漢字を赤色に変えるものです。

手順

  1. Application.ScreenUpdating = False

    • 画面の更新を停止して、処理を速くします。

  2. 変数の宣言

    • myRng:選択したセル範囲を表します。

    • myStr:セルの文字列を一時的に格納します。

    • i:文字列を2文字ずつ確認するためのカウンターです。

  3. 選択範囲内のセルを1つずつ確認

    • `For Each myRng In Selection`:選択範囲内の各セルを順番に処理します。

  4. セルの文字列を2文字ずつ確認

    • `For i = 1 To Len(myRng)`:セル内の文字列を1文字ずつ確認します。

    • `myStr = Mid(myRng.Value, i, 3)`:セル内の文字列を2文字ずつ切り出します。

  5. 「地下鉄」という文字列を探して赤色に変更

    • `If myStr Like "地下鉄" Then`:文字列が「地下鉄」と一致するか確認します。

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

  6. Application.ScreenUpdating = True

    • 最後に画面の更新を再開します。

このプロシージャは、Excelの基本操作ができる方なら簡単に使いこなせるように作られています。プログラミングに興味がある方にとって、セルの文字列を検索して書式を変更するという基本的な操作を理解する良い機会です。

Excel VBA リファレンス | Microsoft Learn
この記事のYouTube動画はこちら


英語翻訳

Sub Highlight "Subway" in Red

This explanation is created using ChatGPT.

This procedure changes the color of the kanji "地下鉄" (subway) to red in the selected cells in Excel.

Steps

  1. Application.ScreenUpdating = False

    • Stops screen updating to speed up the process.

  2. Variable Declaration

    • myRng: Represents the selected cell range.

    • myStr: Temporarily stores the string from the cell.

    • i: Counter to check the string two characters at a time.

  3. Check Each Cell in the Selection

    • `For Each myRng In Selection`: Processes each cell in the selected range one by one.

  4. Check the String in the Cell Two Characters at a Time

    • `For i = 1 To Len(myRng)`: Checks each character in the cell's string.

    • `myStr = Mid(myRng.Value, i, 3)`: Extracts the string two characters at a time from the cell.

  5. Find the String "地下鉄" and Change Its Color to Red

    • `If myStr Like "地下鉄" Then`: Checks if the string matches "地下鉄".

    • `With myRng.Characters(Start:=i, Length:=3).Font`: If it matches, changes the font color of that part to red (ColorIndex = 3).

  6. Application.ScreenUpdating = True

    • Finally, resumes screen updating.

This procedure is designed to be easy for anyone with basic Excel skills to use. For those interested in programming, it’s a good opportunity to understand the basic operation of searching for a string in a cell and changing its format.

Excel VBA Reference | Microsoft Learn
Watch this YouTube video


キーワード

#excel #できること #vba #地下鉄 #漢字 #赤色にする #文字列検索 #書式変更 #セル操作 #基本操作 #プログラミング初心者 #Excelマクロ #条件付き書式 #セルのフォーマット #VisualBasic #VBAチュートリアル #初心者向けVBA #文字色変更 #Excelテクニック #Officeスクリプト

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