IF Statement giving a Syntax Error

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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.
 
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)
 
Prima!
Thank you Tom and Bob, it works like a dream.

Bob Phillips said:
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 said:
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
 

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