Solved

Excel 2007 VBA error 1004

Posted on 2014-03-05
7
644 Views
Last Modified: 2014-03-05
I am trying to insert a formula that checks for a 'Y' in a cell and I get the above error so the syntax must be wrong: -
ActiveCell.Formula = "=IF(AA3.value='Y' etc.

Can anyone help?
0
Comment
Question by:HKFuey
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 19

Expert Comment

by:regmigrant
ID: 39905935
possible reasons:-
- you have the sheet protected
- your formula is incorrect (missing bracket or parameter)

Can you post an example - or at least complete  code lines  above and below
0
 

Author Comment

by:HKFuey
ID: 39905956
OK full formula: -
ActiveCell.Formula = "=IF(AA3.value='Y',(((V3+I3+J3+K3)-(L3+M3+N3+O3))*-1)+C3,((V3+I3+J3+K3)-(L3+M3+N3+O3))*-1)"

It was this: ((V3+I3+J3+K3)-(L3+M3+N3+O3))*-1

The iff statement breaks it so 'AA3.value='Y'' must be wrong
0
 
LVL 19

Expert Comment

by:regmigrant
ID: 39905961
the formula within the " must be a valid excel formula on it own - ie: you should be able to cut it from the code and put it in a cell - if you do that the error generated will highlight what is wrong with the formula.

a couple of guesses:

- if you are looking at the value in AA3 then use it as though in the spreadsheet:
 = "=if(AA3 = 'Y'.....


- if aa3.value is an object or variable from within the script and you want to use its current value:
 "=if(" & aa3.value & "='Y'....
0
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 

Author Comment

by:HKFuey
ID: 39905981
OK to simplify, this still gives the error: -

ActiveCell.Formula = "=IF(AA3='Y','Y','')"
0
 
LVL 19

Accepted Solution

by:
regmigrant earned 500 total points
ID: 39905993
I think that is a problem with using single quote vs double quote - excel needs double quotes in the formula

to 'escape' a double quote you need a double double quote :-

""""

so:
"=IF(AA3=""""Y"""",""""Y"""",""""""""')"

or set a string for qt = """" and then concatenate the formula - because its difficult to keep count.

"=if(aa3=" & qt & "Y" & qt & "," & qt & "Y" & qt & "," & qt & qt & ")"

not an uncommon problem - and very messy

http://stackoverflow.com/questions/216616/how-to-create-strings-containing-double-quotes-in-excel-formulas
0
 

Author Comment

by:HKFuey
ID: 39905994
Got there nearly same time! Answer is also here: -
http://www.ozgrid.com/forum/showthread.php?t=42515
0
 

Author Closing Comment

by:HKFuey
ID: 39905995
Thanks!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

627 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question