using if statement to compare text

  • Thread starter Thread starter josh
  • Start date Start date
J

josh

My program is supposed to read dates out of the spreadsheet, but
sometimes there are text strings instead. On these instances I need to
write an if statement telling the program to go elsewhere when it
encounters this string. This may be really simple, but when i type
If MyDate = "TK" then
blah blah blah....


i get a mismatch error on the "TK" part. am i doing something wrong
there? what is the proper way to compare a text string to a variable.
and i know MyDate is getting the "tk" cause i had a message box pop up
to tell me the value of it right above it.

thanks
 
How have you declared the variable MyDate? I suspect you declared
it as a numeric type or as Date. Try changing it to Variant.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
Make sure that myDate is not declared as a Date, but as a variant, to be
able to handle different data types.

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)
 
I tried changing it to a variant and got the same error. here is the
code...


ActiveCell.Value = mydate
MsgBox (mydate)
If mydate = "TK" Then
MsgBox ("worked")
Else


the cell it's looking at is formatted to date, but has the text "TK" in
it. if that matters.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top