エクセルでユーザー定義関数を作成する、作成したユーザー定義関数を検索するVBAを紹介します。
エクセルで常に使用できるようにアドオンへの登録方法も併せて紹介しています。
![エクセルマクロ](https://ramq-cat.com/wp-content/uploads/2020/11/1484715_s.jpg)
ユーザー定義関数を作成する
![](https://ramq-cat.com/wp-content/uploads/2021/01/084919.jpg)
ユーザー定義関数となるVBAを標準モジュールに書き込んでいきます。
1.「開発」タブ → Visual Basic (もしくは Alt + F11)
![](https://ramq-cat.com/wp-content/uploads/2021/01/76c691c22c7ef40a64aa64b04f05e90c.png)
![](https://ramq-cat.com/wp-content/uploads/2021/01/76c691c22c7ef40a64aa64b04f05e90c.png)
2.「挿入」タブ → 標準モジュール
![](https://ramq-cat.com/wp-content/uploads/2021/01/82cd89bf6e3e7beeac7a6a7e3c296e8a.png)
![](https://ramq-cat.com/wp-content/uploads/2021/01/82cd89bf6e3e7beeac7a6a7e3c296e8a.png)
※必須ではない
関数の検索とは
![](https://ramq-cat.com/wp-content/uploads/2021/01/084919.jpg)
![](https://ramq-cat.com/wp-content/uploads/2021/01/084919.jpg)
![](https://ramq-cat.com/wp-content/uploads/2021/01/084919.jpg)
関数のボタンを押したときに、作成したユーザー定義関数を検索できるようにしたり、数式の入力ガイドが出るようにしたりします。
関数ボタンを押して
![](https://ramq-cat.com/wp-content/uploads/2021/01/82cd89bf6e3e7beeac7a6a7e3c296e8a-1.png)
![](https://ramq-cat.com/wp-content/uploads/2021/01/82cd89bf6e3e7beeac7a6a7e3c296e8a-1.png)
関数を検索できるようにしたり
![](https://ramq-cat.com/wp-content/uploads/2021/01/5bc9fc4d63d4a0ab3f0efe11bd966220-1.png)
![](https://ramq-cat.com/wp-content/uploads/2021/01/5bc9fc4d63d4a0ab3f0efe11bd966220-1.png)
数式の入力ガイドが出たりするようにしていきます。
![](https://ramq-cat.com/wp-content/uploads/2021/01/a88e5b631e0ef8187e3605a9d1a5a789-1.png)
![](https://ramq-cat.com/wp-content/uploads/2021/01/a88e5b631e0ef8187e3605a9d1a5a789-1.png)
![](https://ramq-cat.com/wp-content/uploads/2021/01/084919.jpg)
![](https://ramq-cat.com/wp-content/uploads/2021/01/084919.jpg)
![](https://ramq-cat.com/wp-content/uploads/2021/01/084919.jpg)
こうすることにより作成したユーザー定義関数を、誰でも数式を入力しやすいものにしていきます。
ユーザー定義関数の情報を登録するVBA
1.F11を開き、「ThisWorkbook」をクリックし、VBAを記述するウインドウを開く
![](https://ramq-cat.com/wp-content/uploads/2021/01/2d2e3ff6face4e798a1d0d6dd774d920-1.png)
![](https://ramq-cat.com/wp-content/uploads/2021/01/2d2e3ff6face4e798a1d0d6dd774d920-1.png)
2.プルダウンから「Worknook」と「Open」を選択する
![](https://ramq-cat.com/wp-content/uploads/2021/01/935fa1487c9a157f63f7141b92c39790-1.png)
![](https://ramq-cat.com/wp-content/uploads/2021/01/935fa1487c9a157f63f7141b92c39790-1.png)
Private Sub Workbook_Open()
Application.MacroOptions Macro:=”VBAのタイトル①”, _
Description:=”説明”, _
Category:=”カテゴリー”
Application.MacroOptions Macro:=”VBAのタイトル②”, _
Description:=”説明” & Chr(13) & “説明”, _
Category:=”カテゴリー”
End Sub
一度ファイルを保存し、開くと、関数の中に登録されます。
![](https://ramq-cat.com/wp-content/uploads/2021/01/f1fb298047cd327c13a3640587f384d2-1.png)
![](https://ramq-cat.com/wp-content/uploads/2021/01/f1fb298047cd327c13a3640587f384d2-1.png)
説明:本日を基準として・・・
ユーザー定義関数名の後ろの()に入る名前は、ユーザー定義関数として登録したVBAにならいます。
サンプルは
Function 請求日(締日 as Long, 入金サイト as Long) as Date
・・・
End Function
としています。
ユーザー定義関数を、Excelで常に使用できるようにする(アドインの設定)
1.「開発」タブ → Visual Basic (もしくは Alt + F11)
![](https://ramq-cat.com/wp-content/uploads/2021/01/76c691c22c7ef40a64aa64b04f05e90c.png)
![](https://ramq-cat.com/wp-content/uploads/2021/01/76c691c22c7ef40a64aa64b04f05e90c.png)
2.「挿入」タブ → 標準モジュール
![](https://ramq-cat.com/wp-content/uploads/2021/01/82cd89bf6e3e7beeac7a6a7e3c296e8a.png)
![](https://ramq-cat.com/wp-content/uploads/2021/01/82cd89bf6e3e7beeac7a6a7e3c296e8a.png)
ファイルはアドイン用のフォルダに保存されます。
例 C:\Users*****\AppData\Local\Packages\Microsoft.Office.Desktop_8wekyb3d8bbwe\LocalCache\Roaming\Microsoft\AddIns\TEXTJOIN.xlam
1.Excelを開く(新規でも、既存のブックでも可)
2.「ファイル」タブ → オプション
3.アドイン → 設定
![](https://ramq-cat.com/wp-content/uploads/2021/01/5bc9fc4d63d4a0ab3f0efe11bd966220.png)
![](https://ramq-cat.com/wp-content/uploads/2021/01/5bc9fc4d63d4a0ab3f0efe11bd966220.png)
4.作成したアドオン(ここでは「Textjoin」)にチェックを入れる → OK
![](https://ramq-cat.com/wp-content/uploads/2021/01/a88e5b631e0ef8187e3605a9d1a5a789.png)
![](https://ramq-cat.com/wp-content/uploads/2021/01/a88e5b631e0ef8187e3605a9d1a5a789.png)
![](https://ramq-cat.com/wp-content/uploads/2021/01/2d2e3ff6face4e798a1d0d6dd774d920.png)
![](https://ramq-cat.com/wp-content/uploads/2021/01/2d2e3ff6face4e798a1d0d6dd774d920.png)
![](https://ramq-cat.com/wp-content/uploads/2021/01/084919.jpg)
![](https://ramq-cat.com/wp-content/uploads/2021/01/084919.jpg)
![](https://ramq-cat.com/wp-content/uploads/2021/01/084919.jpg)
これでユーザー定義関数が、このPC上で使えるようになりましたので、式を入力して使ってみてください。
コメント