Private Sub CommandButton5_Click()

'CAS検索ボタン
Dim i As Long
Dim 最終行 As String
Dim サーチ行 As Long
Dim 最終行2 As String

Set xlBook = Workbooks.Open("C:\Users\coco\Desktop\物質管理\book1.xls")

'Sheets("data").Activate
最終行 = Range("D3").End(xlDown).Row
サーチ行 = 0
For i = 2 To 最終行
If TextBox1.Value = Range("D" & i) Then
TextBox2.Text = Range("E" & i)
TextBox9.Text = Range("H" & i)
TextBox4.Text = Range("I" & i)
TextBox45.Text = Range("AS" & i)
TextBox41.Text = Range("G" & i)
TextBox46.Text = Range("B" & i)

TextBox42.Value = ""
TextBox43.Value = ""
TextBox44.Value = ""


サーチ行 = i
Exit For

End If
Next

 

If サーチ行 = 0 Then
MsgBox TextBox1.Value & "物質名はありません。", vbInformation, "該当無し"
End If
If TextBox34.Value = "禁止レベル1" Then

TextBox34.ForeColor = RGB(255, 0, 0)
End If


TextBox1.SetFocus
End Sub

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

Private Sub CommandButton5_Click()
'CAS番号検索ボタン

Dim i As Long
Dim 最終行 As String
Dim サーチ行 As Long

Sheets("data").Activate
最終行 = Range("D3").End(xlDown).Row
サーチ行 = 0
For i = 2 To 最終行
If TextBox1.Value = Range("D" & i) Then
TextBox2.Text = Range("E" & i)

TextBox3.Text = Range("F" & i)

サーチ行 = i
Exit For
End If
Next
If サーチ行 = 0 Then
MsgBox TextBox1.Value & "登録されていません。", vbInformation, "新規購入入力してください。"
End If

TextBox1.SetFocus

End Sub

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