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

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Excel VBA syntax problem

Reply to Message Icon

Name: Erik Mills
Date: April 25, 2003 at 08:06:32 Pacific
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?



Sponsored Link
Ads by Google

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

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.


0

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

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


0

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

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


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Excel VBA syntax problem

Excel VBA Problem saving file www.computing.net/answers/programming/excel-vba-problem-saving-file-/14722.html

excel vba macro assistance www.computing.net/answers/programming/excel-vba-macro-assistance/10837.html

Excel-VBA problem www.computing.net/answers/programming/excelvba-problem/3695.html