Solved

Excel 2007 VBA error 1004

Posted on 2014-03-05
7
641 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

729 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