Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default IF Statement giving a Syntax Error

I need to find the quarter of a known date.

This code works fine:
ActiveCell.FormulaR1C1 =
"=IF(MONTH(R[-26]C)<=3,4,IF(MONTH(R[-26]C)<=6,1,IF(MONTH(R[-26]C)<=9,2,3)))"

But I need the result to be ordinal, so I substituted "fourth", "third" etc
for the numbers:
ActiveCell.FormulaR1C1 =
"=IF(MONTH(R[-26]C)<=3,€¯fourth€¯,IF(MONTH(R[-26]C)<=6,€¯first€¯,IF(MONTH(R[-26]C)<=9,€¯second€¯,€¯third€¯)))"
Although it works in the formual bar it produced a synatx error in code.

Any clues as to how to fix this?
I've tried formatting the cell, which gives a fix in Excel but this doesn't
copy across to Word in the same format.

Thanks in advance
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default IF Statement giving a Syntax Error

You have to double the double quotes inside a string. Make sure you are
below row 26.

ActiveCell.FormulaR1C1 =
"=IF(MONTH(R[-26]C)<=3,""fourth"",IF(MONTH(R[-26]C)<=6,""first"",IF(MONTH(R[-26]C)<=9,""second"",""third"")))"

worked fine for me.

--
Regards,
Tom Ogilvy


"Jimbob" wrote:

I need to find the quarter of a known date.

This code works fine:
ActiveCell.FormulaR1C1 =
"=IF(MONTH(R[-26]C)<=3,4,IF(MONTH(R[-26]C)<=6,1,IF(MONTH(R[-26]C)<=9,2,3)))"

But I need the result to be ordinal, so I substituted "fourth", "third" etc
for the numbers:
ActiveCell.FormulaR1C1 =
"=IF(MONTH(R[-26]C)<=3,€¯fourth€¯,IF(MONTH(R[-26]C)<=6,€¯first€¯,IF(MONTH(R[-26]C)<=9,€¯second€¯,€¯third€¯)))"
Although it works in the formual bar it produced a synatx error in code.

Any clues as to how to fix this?
I've tried formatting the cell, which gives a fix in Excel but this doesn't
copy across to Word in the same format.

Thanks in advance

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default IF Statement giving a Syntax Error

Double-up on the quotes. For example

""fourth""

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Jimbob" wrote in message
...
I need to find the quarter of a known date.

This code works fine:
ActiveCell.FormulaR1C1 =
"=IF(MONTH(R[-26]C)<=3,4,IF(MONTH(R[-26]C)<=6,1,IF(MONTH(R[-26]C)<=9,2,3)))"

But I need the result to be ordinal, so I substituted "fourth", "third"
etc
for the numbers:
ActiveCell.FormulaR1C1 =
"=IF(MONTH(R[-26]C)<=3,"fourth",IF(MONTH(R[-26]C)<=6,"first",IF(MONTH(R[-26]C)<=9,"second","third")))"
Although it works in the formual bar it produced a synatx error in code.

Any clues as to how to fix this?
I've tried formatting the cell, which gives a fix in Excel but this
doesn't
copy across to Word in the same format.

Thanks in advance



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default IF Statement giving a Syntax Error

Prima!
Thank you Tom and Bob, it works like a dream.

"Bob Phillips" wrote:

Double-up on the quotes. For example

""fourth""

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Jimbob" wrote in message
...
I need to find the quarter of a known date.

This code works fine:
ActiveCell.FormulaR1C1 =
"=IF(MONTH(R[-26]C)<=3,4,IF(MONTH(R[-26]C)<=6,1,IF(MONTH(R[-26]C)<=9,2,3)))"

But I need the result to be ordinal, so I substituted "fourth", "third"
etc
for the numbers:
ActiveCell.FormulaR1C1 =
"=IF(MONTH(R[-26]C)<=3,"fourth",IF(MONTH(R[-26]C)<=6,"first",IF(MONTH(R[-26]C)<=9,"second","third")))"
Although it works in the formual bar it produced a synatx error in code.

Any clues as to how to fix this?
I've tried formatting the cell, which gives a fix in Excel but this
doesn't
copy across to Word in the same format.

Thanks in advance




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Any idea why this is giving me a #Value! Error? msnyc07 Excel Worksheet Functions 3 March 12th 10 05:22 PM
Giving me a error ( =REF! ) Steved Excel Worksheet Functions 2 October 5th 09 01:10 AM
Syntax error in nested IF statement. Sander Excel Discussion (Misc queries) 5 July 15th 09 10:21 PM
syntax error in case statement? Janis Excel Programming 1 September 20th 06 06:22 PM
Function giving error Martin Excel Discussion (Misc queries) 3 October 1st 05 12:58 PM


All times are GMT +1. The time now is 05:01 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"