Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 50117

How to open msgBox and close UserForm if no data found

$
0
0
Hi all,
I'm trying to open the workbook base on Cell value and I would like to open MsgBox and close UserForm if the file does not exsit.

Regards,
tt3
Code:

Private Sub tt3_Click()
Sheets("Sheet1").Range("N2").Value = UserForm.TextBox2.Value

If Sheets("Sheet1").Range("N2").Value = False Then
MsgBox "Please enter Vehicle info"
UserForm.Hide
End If

If Not "Y:\Testing\" & ThisWorkbook.Sheets("Sheet1").Range("N2").Value & ".xlsm" Then
MsgBox " This Vehicle does not exist "
UserForm.Hide
End If

Else
Workbooks.Open Filename:="Y:\Testing\" & ThisWorkbook.Sheets("Sheet1").Range("N2").Value & ".xlsm"
UserForm.Hide

End Sub


Viewing all articles
Browse latest Browse all 50117