Display date serial number using TEXT in IF

0

I am using an IF function to insert a string into a cell if the cell specified is #N/A, the function works if I use the following

=IF(AS2="#N/A","",CONCATENATE("insert in tempTable values('",AQ2,"','",AR2,"')"))

where AR2 is the date, here are the two different strings I am being returned

insert in tempTable values('BIXEN V VASILE ALIN GEORGESCU','19/3/2012')
insert in tempTable values('BANEKIOSKEN V MUHAMMAD NASEEB KHAN','41003')

the problem is some of the dates are ok where others are in the date serial number format so I am trying to use the TEXT function to change this on the following function it is not working

=IF(AS2="#N/A","",CONCATENATE("insert in tempTable values('",AQ2,"','",TEXT(AR2,d/m/yyyy),"')"))

i have also tried

=IF(AS2="#N/A","",CONCATENATE("insert in tempTable values('",AQ2,"','",IF(AR2=d/m/yyyy,AR2,TEXT(AR2,d/m/yyyy)),"')"))

Does anyone see what I am doing wrong?

EDIT: here is the formula working

=IF(AS2="#N/A","",CONCATENATE("insert in tempTable values('",AQ2,"','",IF(AR2="d/m/yyyy",AR2,TEXT(AR2,"d/m/yyyy")),"')"))

flexinIT

Posted 2012-09-18T09:58:24.657

Reputation:

Surely AR2 won't ever be equal to "d/m/yyyy" (which is what you are checking - it isn't checking the format). If AR2 is a "date" in text format then TEXT function won't change it. I'd try this version =IF(ISNA(AS2),NA(),CONCATENATE("insert in tempTable values('",AQ2,"','",TEXT(AR2,"d/m/yyyy"),"')")) That will also explicitly return #N/A which is "cleaner" than allowing the error, I think – barry houdini – 2012-09-18T10:22:42.720

Answers

1

You need quotes around the date format, ie

TEXT(AR2,"d/m/yyyy")

BTW you can use ISNA(AS2) rather than AS2="#N/A"

Or even (in Excel 2007+)

IFERROR(AS2,CONCATENATE( ... ), "")

chris neilsen

Posted 2012-09-18T09:58:24.657

Reputation: 4 005

yes this solved it alright, never spotted that at all, cheers... i know i can use the ISNA() function but that removes the #N/A from the cell then when I actually need the #N/A in the cell so i can remove the lines in notepad++ using these #N/A's – None – 2012-09-18T10:10:18.300

What I ment was =IF(ISNA(AS2),"",CONCATENATE( .... this has no effect of the source cell AS2 – chris neilsen – 2012-09-18T10:23:02.767