Type mismatch error with use of cdate

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,564
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Perhaps I'm using cdate incorrectly. I wish to take the text date from a userform control ("processdate") and convert it to date serial.
Rich (BB code):
me.processdate.value="Tuesday, January 23, 2018"

My code:
Rich (BB code):
Private Sub Label834_Click()
    Dim uid
    uid = CDate(processdate.Value)
End Sub

I am getting a 'type mismatch' error with the line in red.

Is it my textual representation of the date which is complicating things?
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
because that is not a date. Its a string that looks like a date.
remove the Day of Week and it will behave like a date....

vDate= Mid(me.processdate.value, InStr(me.processdate.value, ",") + 1)
 
Upvote 0
The Tuesday is stopping the recognition of the date. Extract just the January 23, 2018 and cdate will work

Code:
Dim uid As Date
uid = CDate(Trim(Mid(processdate, InStr(processdate, ",") + 1, 9999)))
 
Upvote 0
I would never have hammered that out on my own.
Thank you both!!
 
Upvote 0

Forum statistics

Threads
1,215,419
Messages
6,124,796
Members
449,189
Latest member
kristinh

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