ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Using IsError (https://www.excelbanter.com/excel-programming/435899-using-iserror.html)

Merlynsdad

Using IsError
 
I have two list boxes for users to select dates, and want to use IsError to
generate a msgbox if the user tries to run the code without selecting a date.
The current code is:

If CDate(lstTo) < CDate(lstFrom) Then
MsgBox "The 'To' date should not be before the 'From' date!"
End If

This covers the user entering the dates backwards, but how do I make this
work if the user omits the dates completely?



Mike H

Using IsError
 
Hi,

One way

If Not IsDate(lstTo) Or Not IsDate(lstFrom) Then
MsgBox "You must enter 2 dates!"
ElseIf CDate(lstTo) < CDate(lstFrom) Then
MsgBox "The 'To' date should not be before the 'From' date!"
End If

Mike

"Merlynsdad" wrote:

I have two list boxes for users to select dates, and want to use IsError to
generate a msgbox if the user tries to run the code without selecting a date.
The current code is:

If CDate(lstTo) < CDate(lstFrom) Then
MsgBox "The 'To' date should not be before the 'From' date!"
End If

This covers the user entering the dates backwards, but how do I make this
work if the user omits the dates completely?




All times are GMT +1. The time now is 08:55 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com