Select Case Criteria based on cell contents question

Pinaceous

Well-known Member
Joined
Jun 11, 2014
Messages
1,111
Office Version
  1. 365
Platform
  1. Windows
Hello,

I'm trying to construct a Select Case that is based on the contents of a cell.

For example, in using cell A1, if a user enters in a date item versus a non-date entry into that cell it will produce:

Code:
Case; If cell A1; if it has a date entry then  MsgBox "Date".

Case; If cell A1; if it is not a date entry then  MsgBox "This is not a Date".



Can someone please help me construct a Select Case for this type of situation?

Many thanks in advance,
pinaceous
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Within the scope of the IsDate function (which is described below the code)
Code:
Sub Pinaceous()
Select Case True
    Case IsDate([A1]): MsgBox "Date"
    Case Else: MsgBox "This is not a date"
End Select
End Sub
From VBA Help:
IsDate Function

<tbody>
</tbody>

Returns a Boolean value indicating whether an expression can be converted to a date.
Syntax
IsDate(expression)
The required expression argument is a Variant containing a date expression or string expression recognizable as a date or time.
Remarks
IsDate returns True if the expression is a date or is recognizable as a valid date; otherwise, it returns False. In Microsoft Windows, the range of valid dates is January 1, 100 A.D. through December 31, 9999 A.D.; the ranges vary among operating systems.

 
Upvote 0
Thank you for the code JoeMo!

Could you add to this code, whereby if the cell of A1 is blank [that is Formatted for the Date *Wednesday, March 14, 2014], it returns MsgBox "This cell is blank"?


Thanks again,
Paul
 
Upvote 0
You are welcome. The revision below covers the blank cell addition.
Code:
Sub Pinaceous()
Select Case True
    Case IsDate([A1]): MsgBox "Date"
    Case Else
        If IsEmpty(Range("A1")) Then
            MsgBox "This cell is blank"
        Else
            MsgBox "This is not a date"
        End If
End Select
End Sub
 
Upvote 0
Thanks JoeMo!


That worked out really well, many thanks for helping me out!

Paul
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,733
Members
448,987
Latest member
marion_davis

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top