Private Sub CommandButton1_Click()
On Error Resume Next
'輸入員工編號後用 函數來取得員工姓名
ranme = sht2.Cells(WorksheetFunction.Match(TextBox3.Text, sht2.Range("D:D"), 0), "E")
'如果查無員工編號,要求重新輸入員工編號
If ranme = "" Then
MsgBox "查無員工編號,請重新輸入"
UserForm1.TextBox3.Text = ""
UserForm1.TextBox3.SetFocus
Exit Sub
End If
On Error GoTo 0
With sht1
.Range("A2") = Me.ComboBox1.List(Me.ComboBox1.ListIndex, 0)
.Range("A4") = Me.ComboBox1.List(Me.ComboBox1.ListIndex, 1)
.Range("B4") = TextBox2.Text
.Range("B7") = ranme '這裡是TextBox3轉寫地方
End With
End Sub