見出し画像

給与形態のプルダウンを設定するよ

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

このプロシージャは、Excelのセルに給与形態を選択できるプルダウンリストを設定するものです。実行すると、選択したセルに「時給」「月給」「年俸」「日給」のいずれかを選択できるリストが表示されます。

仕組みの説明

  1. 画面更新を停止
    `Application.ScreenUpdating = False`
    これにより、コードの実行中に画面がチラつかないようにします。

  2. 選択範囲のデータ検証設定
    `With Selection.Validation`
    この部分では、選択されたセルに対してデータ検証の設定を行います。

    • 既存のデータ検証を削除
      `.Delete`
      既存のデータ検証ルールを削除します。

    • 新しいリストを追加
      `.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:="時給,月給,年俸,日給"`
      リストから選択できるようにデータ検証ルールを追加します。このリストには「時給」「月給」「年俸」「日給」の4つの項目が含まれています。

    • 空白の無視とドロップダウン表示の設定
      `.IgnoreBlank = True`
      `.InCellDropdown = True`
      空白を無視し、セル内にドロップダウンリストを表示します。

    • 入力メッセージとエラーメッセージの設定
      `InputTitle`や`ErrorTitle`を空にし、入力メッセージやエラーメッセージも表示しないように設定しています。

    • その他の設定
      `.IMEMode = xlIMEModeNoControl`
      `.ShowInput = False`
      `.ShowError = False`
      IMEのモードを制御せず、入力時のメッセージやエラーメッセージを表示しないようにします。

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

このプロシージャを使うと、給与形態を簡単に選択できるようになり、入力ミスを減らすことができます。


Translation in English

Set Dropdown for Salary Types

This explanation is created by ChatGPT.

This procedure sets a dropdown list in an Excel cell where you can select the type of salary. When executed, it displays a list in the selected cell from which you can choose "Hourly", "Monthly", "Annual", or "Daily".

Explanation of the Mechanism

  1. Stop Screen Updating
    `Application.ScreenUpdating = False`
    This prevents the screen from flickering during the code execution.

  2. Set Data Validation for the Selected Range
    `With Selection.Validation`
    This part sets data validation for the selected cell.

    • Delete Existing Data Validation
      `.Delete`
      Deletes existing data validation rules.

    • Add a New List
      `.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:="Hourly,Monthly,Annual,Daily"`
      Adds a data validation rule to allow selection from a list. This list includes "Hourly", "Monthly", "Annual", and "Daily".

    • Set Ignore Blank and Show Dropdown
      `.IgnoreBlank = True`
      `.InCellDropdown = True`
      Ignores blanks and displays a dropdown list in the cell.

    • Set Input and Error Messages
      The `InputTitle` and `ErrorTitle` are left empty, and input and error messages are set not to be displayed.

    • Other Settings
      `.IMEMode = xlIMEModeNoControl`
      `.ShowInput = False`
      `.ShowError = False`
      The IME mode is not controlled, and input and error messages are not displayed.

  3. Resume Screen Updating
    `Application.ScreenUpdating = True`
    Finally, the screen updating is resumed.

Using this procedure makes it easier to select the type of salary and reduces input errors.


Excel VBA リファレンス | Microsoft Learn

この記事のYouTube動画はこちら

キーワード

#excel #できること #vba #データ検証 #プルダウンリスト #給与形態 #時給 #月給 #年俸 #日給 #入力ミス防止 #エクセル #マクロ #プログラミング初心者 #効率化 #自動化 #画面更新停止 #入力補助 #データ入力 #ExcelVBA

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