見出し画像

線と駅があったらそれだけ赤色にするよ

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

このプロシージャは、Excelシート上で選択されたセルの中に「線」や「駅」という文字が含まれている場合、その文字だけを赤色にするものです。以下にその仕組みを詳しく説明します。

  1. 画面の更新を一時停止
    プロシージャの最初と最後で、`Application.ScreenUpdating`を`False`と`True`に設定することで、処理中の画面のちらつきを防ぎ、処理速度を向上させます。

  2. 変数の宣言

    • `myRng`: 選択されたセル範囲内の各セルを参照するための変数。

    • `myStr`: 各セル内の文字を1文字ずつ取り出すための変数。

    • `i`: 各セル内の文字を1文字ずつ調べるためのループカウンタ。

    • `a`: このプロシージャでは使われていませんが、長整数型の変数として宣言されています。

  3. 画面の更新を再開
    最後に、`Application.ScreenUpdating`を`True`に戻して、画面の更新を再開します。

  4. 特定の文字を探して赤色に変更
    各セル内の1文字(`myStr`)を取り出し、それが「線」または「駅」であるかを調べます。該当する場合、その文字のフォントカラーを赤色(`ColorIndex = 3`)に変更します。

If myStr Like "線" Or myStr Like "駅" Then
    With myRng.Characters(Start:=i, Length:=1).Font
        .ColorIndex = 3
    End With
End If

5.画面の更新を再開
最後に、`Application.ScreenUpdating`を`True`に戻して、画面の更新を再開します。


キーワード
#excel #できること #vba #セル内文字列 #特定文字検索 #フォントカラー変更 #画面更新 #処理速度向上 #変数宣言 #選択範囲処理 #文字色変更 #プログラミング初心者 #簡単VBA #赤色変更 #文字フォーマット #セル操作 #Excel自動化 #初心者向け #基本操作 #プログラミング学習


Highlighting Characters "線" and "駅" in Red

This explanation is created with ChatGPT.

This procedure highlights the characters "線" and "駅" in red within selected cells in an Excel sheet. Here's a detailed explanation of how it works:

  1. Temporarily Disable Screen Updating
    By setting `Application.ScreenUpdating` to `False` at the start and `True` at the end, the procedure prevents screen flickering and improves processing speed during execution.

  2. Variable Declaration

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

    • `myStr`: Used to extract each character from the cell.

    • `i`: Loop counter to examine each character in the cell.

    • `a`: Declared but not used in this procedure, intended as a long integer variable.

  3. Re-enable Screen Updating
    Finally, `Application.ScreenUpdating` is set back to `True` to resume screen updating.

  4. Find Specific Characters and Change to Red
    The procedure extracts each character (`myStr`) from the cell and checks if it is "線" or "駅". If so, it changes the font color of that character to red (`ColorIndex = 3`).

If myStr Like "線" Or myStr Like "駅" Then
    With myRng.Characters(Start:=i, Length:=1).Font
        .ColorIndex = 3
    End With
End If

5.Re-enable Screen Updating
Finally, `Application.ScreenUpdating` is set back to `True` to resume screen updating.



Keywords
#excel #できること #vba #celltext #specificcharactersearch #fontcolorchange #screenupdating #processingspeedimprovement #variabledeclaration #selectionprocess #charactercolorchange #programmingbeginner #easyvba #redcolorchange #textformat #celloperation #excelautomation #beginnerfriendly #basicoperation #learnprogramming

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