見出し画像

未経験だけを赤字にするよ

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

このVBAプロシージャ「未経験だけを赤字にするよ」は、Excelのシート上で選択した範囲内にある「未経験」という文字を見つけて、その部分だけを赤い文字にする仕組みです。PC操作が基本的なレベルでも、プログラムの働きを理解することができるように、簡単に説明しますね。


1. 動作の概要

  • Application.ScreenUpdating = False
    これは、処理を高速化するために一時的に画面の更新を止めています。画面がちらつくのを防ぎます。

  • For Each myRng In Selection
    選択されているセル範囲(Selection)の一つ一つのセル(myRng)を順番に処理しています。

  • For i = 1 To Len(myRng)
    それぞれのセルの中の文字を一文字ずつチェックしていきます。*Len(myRng)*は、そのセルの中にある文字数を示しています。

  • myStr = Mid(myRng.Value, i, 3)
    この部分では、セルの中の文字列の中から「未経験」という3文字を取り出して、その部分をmyStrという変数に一時的に保存しています。

  • If myStr Like "未経験"
    「未経験」という文字列が見つかった場合、次の処理を実行します。

  • myRng.Characters(Start:=i, Length:=3).Font.ColorIndex = 3
    この部分で、「未経験」という文字の色を赤(ColorIndex = 3)に変更します。ここで、Start:=i は「未経験」が始まる場所を指し、Length:=3 はその長さを指定しています。

  • Application.ScreenUpdating = True
    最後に、画面更新を再開して、変更内容を画面に反映させます。


2. エラーハンドリング

  • On Error Resume Next
    もしエラーが発生しても、処理を止めずに次に進むようにしています。たとえば、セルが空だった場合でも、エラーで止まることなく処理が続行されます。


このプロシージャは、選択した範囲内で「未経験」という文字列を探し、それを見つけたら赤色に変える非常にシンプルなVBAのコードです。Excelでデータを効率的に整理したいときに役立つ内容です!



#excel #できること #vba #文字色変更 #未経験 #セル操作 #選択範囲 #エクセルマクロ #文字列検索 #色変更 #自動化 #画面更新停止解除 #条件指定 #プログラミング初心者 #セル操作 #データ整理 #高速処理 #エラーハンドリング #初心者向けVBA #赤字変更


英語訳


Highlight "未経験" in Red

This explanation was created using ChatGPT.

The VBA procedure "Highlight '未経験' in Red" is designed to find the phrase "未経験" (which means "inexperienced" in Japanese) within the selected cells in an Excel worksheet and change the color of only that phrase to red. Even if you are only familiar with basic PC operations, you can understand how this program works.


1. How it works

  • Application.ScreenUpdating = False
    This temporarily stops screen updating to make the process faster and prevent flickering during execution.

  • For Each myRng In Selection
    This line goes through each cell in the currently selected range (Selection) one by one (stored in the variable myRng).

  • For i = 1 To Len(myRng)
    This checks each character in the cell individually. Len(myRng) returns the total number of characters in the cell.

  • myStr = Mid(myRng.Value, i, 3)
    This line extracts a substring of 3 characters starting from the current position in the cell’s text, and stores it in the variable myStr.

  • If myStr Like "未経験"
    If the substring matches "未経験," the following actions are triggered.

  • myRng.Characters(Start:=i, Length:=3).Font.ColorIndex = 3
    This changes the font color of the "未経験" text to red (ColorIndex = 3). Start:=i specifies where "未経験" starts, and Length:=3 indicates that it spans three characters.

  • Application.ScreenUpdating = True
    Finally, this turns screen updating back on, reflecting the changes visually.


2. Error Handling

  • On Error Resume Next
    This ensures that the process continues even if an error occurs, such as when a cell is empty, without stopping the program.


This procedure is a simple VBA code that searches for the string "未経験" within the selected range and changes it to red. It’s useful when you want to efficiently organize data in Excel!



#excel #whatyoucando #vba #textcolorchange #inexperienced #celloperations #selectedrange #excelmacro #textsearch #colorchange #automation #screenupdatecontrol #conditionalformatting #beginnerprogramming #celloperations #dataorganization #fastprocessing #errorhandling #beginnerfriendlyvba #highlightinred

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