'入力------------------------

Private Sub CommandButton1_Click()

'登録ボタン
Dim 行 As Long
Dim 列 As Long

Workbooks.Open Filename:=ThisWorkbook.Path & "\データ物質試薬管理.xls"


Sheets("inputdata").Select
 
 If TextBox1.Value = "" Then
 MsgBox "CAS番号を入力してください。"
 
 ElseIf TextBox4.Value = "" Then
 
 MsgBox "購入日を入力してください。"
 
 ElseIf TextBox5.Value = "" Then
  MsgBox "購入者を入力してください。"

  ElseIf TextBox6.Value = "" Then
 
  MsgBox "購入量を入力してください。"
 
  ElseIf TextBox8.Value = "" Then
 
  MsgBox "使用量がない場合は「0」を入力してください。"

  ElseIf TextBox8.Value <> "" Then

 

Range("A65536").End(xlUp).Offset(1).Select

行 = ActiveCell.Row
列 = ActiveCell.Column


If IsDate(UserForm1.TextBox4.Value) = False Then
MsgBox "西暦/月/日のように入力してください。"
Exit Sub

Else
Cells(行, 列) = UserForm1.TextBox1.Value

Cells(行, 列 + 1) = UserForm1.TextBox4.Value  '購入日
End If

Cells(行, 列 + 2) = UserForm1.TextBox5.Value '購入者
Cells(行, 列 + 3) = UserForm1.TextBox6.Value '購入量
Cells(行, 列 + 4) = UserForm1.TextBox8.Value '使用量
Workbooks("データ物質試薬管理.xls").Close savechanges:=True

UserForm1.TextBox1.SetFocus

'テキストをクリアにする
TextBox3.Value = ""
TextBox4.Value = ""
TextBox5.Value = ""
TextBox6.Value = ""
TextBox7.Value = ""
TextBox8.Value = ""

TextBox1.SetFocus
MsgBox "登録しました。"
End If

End Sub

 

'---------------------------------------------------------------------------------------