Computing.Net > Forums > Programming > Excel VBA syntax problem

Excel VBA syntax problem

Reply to Message Icon

Original Message
Name: Erik Mills
Date: April 25, 2003 at 08:06:32 Pacific
Subject: Excel VBA syntax problem
OS: Win 2000
CPU/Ram: 1.7hgz
Comment:

I have an excel programming problem I can't seem to get. I have a spreadsheet with the following cell formula that works fine:
=IF(C20="","No Quote",RANK(C20,$B20:$N20,1))

In an VBA Macro I have a similar formula without the If Statement, that again works fine:

ActiveCell.FormulaR1C1 = "=RANK(R[-10]C,R[-10]C2:R[-10]C20,1)"

My problem is I need to combine the two. For some reason my syntax seems off and my VBA editor will not accept it. Here is my best guess:

ActiveCell.FormulaR1C1 = "=IF(R[-10]C="", "No Quote",RANK(R[-10]C,R[-10]C2:R[-10]C20,1))"

What am I missing that the debugger will not accept?


Report Offensive Message For Removal


Response Number 1
Name: shawn
Date: April 25, 2003 at 12:22:18 Pacific
Reply: (edit)

Have you tried to use

"ActiveCell.Formula = "

instead of

"ActiveCell.FormulaR1C1 = "

you can enter the formula in the macro just like you would in the cell.


Report Offensive Follow Up For Removal

Response Number 2
Name: Erik Mills
Date: April 25, 2003 at 13:23:35 Pacific
Reply: (edit)

Tried that and didn't work. It seesms to be expecting an end of statement where the comma appears before 'No Quote'


Report Offensive Follow Up For Removal

Response Number 3
Name: Jamon
Date: April 26, 2003 at 01:01:20 Pacific
Reply: (edit)

I guess you have a problem with the quotes. When you place your formula within the quotes, the quote in your formula need a special treatment.

Replace the quotes in your formula with
" & CHR(34) & "

ActiveCell.FormulaR1C1 = "=IF(R[-10]C=" & CHR(34) & CHR(34) & ", " & CHR(34) & "No Quote" & CHR(34) & ",RANK(R[-10]C,R[-10]C2:R[-10]C20,1))"

Alternatively: Replace a single double-quote with a double double-quote. It looks strange, but VBA interprets a double-double quote in a string as CHR(34)

ActiveCell.FormulaR1C1 = "=IF(R[-10]C="""", ""No Quote"",RANK(R[-10]C,R[-10]C2:R[-10]C20,1))"

Regards,
Jamon


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Excel VBA syntax problem

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




Have you ever used OpenOffice?

Yes, as my main suite.
Yes, occationally.
Yes, but only once.
No, never.


View Results

Poll Finishes In 3 Days.
Discuss in The Lounge