見出し画像

試用期間の週間だけ隣列にだすよ

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

このVBAプロシージャは、Excelで選択したセルの中から「○週間」という文字列を探して、その内容を隣の列に出力するものです。

プロシージャの仕組み

  1. 画面更新停止

    • `Application.ScreenUpdating = False` で画面の更新を停止し、処理速度を向上させます。

  2. 正規表現オブジェクトの作成

    • `CreateObject("VBScript.RegExp")` で正規表現を扱うオブジェクトを作成します。

  3. 正規表現の設定

    • `With reg` ブロック内で正規表現のパターンを設定します。ここでは「○週間」を見つけるために `"\d{1,2}週間"` というパターンを設定しています。

  4. エラーハンドリング

    • `On Error Resume Next` でエラーが発生してもプロシージャが止まらないようにします。

  5. セルのループ処理

    • `For Each myRng In Selection` で選択したセルを一つずつループして処理します。

    • 各セルの内容を `txt = myRng.Value` で取得します。

    • `reg.Execute(txt)` で正規表現にマッチする部分を探し、結果を `match` に格納します。

    • マッチした内容がある場合は、`myRng.Offset(0, 1).Value = match(0).Value` でその内容を隣の列に出力します。

  6. 画面更新再開

    • `Application.ScreenUpdating = True` で画面の更新を再開します。



Translation in English

Extract Weeks During Trial Period to Adjacent Column

This explanation is created using ChatGPT.

This VBA procedure is designed to search for strings indicating "○ weeks" in selected Excel cells and output those strings to the adjacent column.

How the Procedure Works

  1. Stop Screen Updating

    • `Application.ScreenUpdating = False` stops screen updating to improve processing speed.

  2. Create Regular Expression Object

    • `CreateObject("VBScript.RegExp")` creates an object to handle regular expressions.

  3. Set Regular Expression Pattern

    • Inside the `With reg` block, the pattern for the regular expression is set. Here, the pattern `"\d{1,2}週間"` is set to find "○ weeks".

  4. Error Handling

    • `On Error Resume Next` ensures the procedure continues running even if an error occurs.

  5. Loop Through Cells

    • `For Each myRng In Selection` loops through each selected cell.

    • The content of each cell is obtained using `txt = myRng.Value`.

    • `reg.Execute(txt)` searches for matches in the text based on the regular expression and stores the results in `match`.

    • If matches are found, the content is output to the adjacent column using `myRng.Offset(0, 1).Value = match(0).Value`.

  6. Resume Screen Updating

    • `Application.ScreenUpdating = True` resumes screen updating.



Hashtags

#excel #vba #できること #正規表現 #セル操作 #テキスト検索 #Excelマクロ #初心者向け #業務効率化 #自動化 #プログラミング #スクリプト #ExcelTips #Excel初心者 #VBAチュートリアル #VBA解説 #プロシージャ #Excel機能 #隣列出力 #条件検索

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