Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
using if statement to compare text
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 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
using if statement to compare text
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 "josh" wrote in message oups.com... 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 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
using if statement to compare text
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) "josh" wrote in message oups.com... 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 |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
using if statement to compare text
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. |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
using if statement to compare text
Didn't you want to try:
dim myDate as Variant mydate = activecell.value josh wrote: 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. -- Dave Peterson |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
IF Statement - compare to coloured cell | Excel Worksheet Functions | |||
using IF statement to compare text | Excel Worksheet Functions | |||
If statement to compare for wildcard value in another cell. | Excel Worksheet Functions | |||
compare TIME in IF statement | Excel Programming | |||
compare time in IF statement | Excel Worksheet Functions |