Excelの「入力フォーム」とは?
Excelでデータ入力をしていくのは、セルごとに直接行うとミスが発生することがよくありますよね。
エクセルでは、より効率よく表作成ができるようユーザーフォームを使用することができます。
名簿や在庫管理など、表にある項目ごとに入力するテンプレートを表示させることで、1人の氏名や1つの在庫ごとに他のデータを全て入力し、簡単で楽に表を作成します。
この記事では、エクセルのデータベースを簡単に入力するためにできる、入力フォームの作り方をご紹介します。

Excelで入力フォームを作成する方法
入力フォームを作成する方法を2つご紹介します。
「フォームボタン」を使う場合と、「VBA」を使う方法です。
フォームボタンを使う場合

ここからは、入力フォームのテンプレートを表示させるための方法です。
先に、Excelの上にあるリボンに「フォーム」のボタンを追加します。


「追加」して「OK」を押します。

これで、入力フォームのテンプレートを使って、表を作成できます。
表の中のセルを選んでアクティブにし、「フォームボタン」をクリックします。
ここでは、新たに入力を追加するケースです。

「新規」をクリックし、表に合わせて入力する項目があるので入力していきます。


新しいデータを追加する時は、このような手順で入力フォームを出して新規でデータを入力していきます。
入力フォームは、様々な種類の表で使えます。
次に別の表での例ですが、入力フォームを使って編集する方法がこちらです。
まず、表の中のセルをクリックします。


入力フォームが現れたら、「検索条件」をクリックします。
編集したい項目に入力します。

編集を終える時には、「閉じる」を押して入力フォームを消します。
編集内容が表の中で反映されているのを確認しましょう。

閉じると表には次のように訂正されています。

修正テープの在庫数が編集されました。
VBAを使う場合
先に、Visual Basicを使うための「開発タブ」を表示させます。








プロジェクトの白い個所を右クリックします。
「挿入」→「ユーザーフォーム」を選びます。

「ラベル1」が設置されます。

必要な項目の数を設置します。

ラベルを全てコントロールキーを押しながらクリックします。
「書式」→「左」のように位置を決めます。



テキストボックスで使用する「コンボボックス」や「チェックボックス」などの例です。

これで、フォームは完成できました。
フォームをExcelシートと関連付けます。

「挿入」→「標準モジュール」を選びます。


UserForm1.Show
End Sub」と入力します。


「Private Sub CommandBut ton2 click()」の次に、「Unload Me」と入力します。
コマンド2の「キャンセル」ボタンの操作を設定できました。
それをExcelで確認してみます。

「挿入ボタン」からもフォームを表示できます。

次に、他の入力も操作できるように「OK」のボタンを設定します。
このように入力します。
「Private Sub CommandButton1_Click()の後に、
Sheets(“sheet1”).Select
i = Cells(Rows.Count, 2).End(xlUp).Row + 1
Cells(i, 2).Value = Me.TextBox1.Value
Cells(i, 3).Value = Me.TextBox2.Value
Cells(i, 4).Value = Me.TextBox3.Value
Cells(i, 6).Value = Me.TextBox4.Value
For j = 1 To 4
Me.Controls(“TextBox” & j).Value = “”
Next」



「OK」をダブルクリックします。
先程と同様に次のように入力して設定します。
Cells(1.5).Value=""
Nextの後に、
「If OptionButton1 = True Then
Cells(i, 7).Value = Me.OptionButton1.Caption
If OptionButton2 = True Then
Cells(i, 7).Value = Me.OptionButton2.Caption
End If
Me.OptionButton1.Value = False
Me.OptionButton2.Value = False 」

