473,394 Members | 2,168 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

End Of Statement Error with VBA formula for Excel

Hi,

I'm simply trying to put a formula in a range of cells in excel using VBA. I have the formula below:
Expand|Select|Wrap|Line Numbers
  1. Sub TimeSpentFormula()
  2.     Range("SR_TimeSpent").Formula = _
  3.       "=IF(OR(SR_DateClosed="CLOSED", _
  4.       SR_DateClosed = "ON HOLD", _
  5.       Resolution = "Open"), _
  6.       "For Confirmation", _
  7.       (SR_DateClosed-SR_DateOpened))"
  8. End Sub
But I get an error "End of Statement" with the word "CLOSED" highlighted in blue. I think it's considering the first quotation mark beside the word "CLOSED" as the end of the whole formula. Any idea how I can avoid this? Thanks for your help.
Sep 22 '12 #1
5 2145
zmbd
5,501 Expert Mod 4TB
iceley11:

When posting any code please select the posted code and click on the <CODE/> button. Refer the posting guidlines.

As for your error... you are using double quotes ( " ) within the string... you need to replace those with single quotes ( ' ):

So it should read (in part:
"=IF(OR(SR_DateClosed="CLOSED", _
SR_DateClosed = "ON HOLD"

Change to read:
"=IF(OR(SR_DateClosed='CLOSED', _
SR_DateClosed = 'ON HOLD'

and so forth
Sep 22 '12 #2
Try this

Expand|Select|Wrap|Line Numbers
  1. Sub TimeSpentFormula()
  2.       Range("SR_TimeSpent").Formula = _
  3.        "=IF(OR(SR_DateClosed=""CLOSED""," & _
  4.        "SR_DateClosed = ""ON HOLD""," & _
  5.        "Resolution = ""Open"")," & _
  6.        """For Confirmation""," & _
  7.        "(SR_DateClosed-SR_DateOpened))"
  8. End Sub
  9.  
Personally i would just write it out instead of trying to separate into multiple lines.
Sep 24 '12 #3
zmbd
5,501 Expert Mod 4TB
In this case, "Doubling", "Escaping", or "Embedding" the double quotes makes for messier code and places an additional loading on the parser.

The single quote replacements as I sugested is the given best practice:
http://bytes.com/topic/access/insigh...-when-use-them
http://msdn.microsoft.com/en-us/libr...ffice.11).aspx
Sep 24 '12 #4
I quote from Neopa's post,

"A string in VBA requires the Double-Quote (") to delimit it. Single-Quotes (') won't work."

If you try creating a formula in excell with single quotes it will not work because it doesn't convert it to a string, and the formula fails.
Sep 24 '12 #5
zmbd
5,501 Expert Mod 4TB
you're absolutly correct, for some reason I didn't read it as an excel formula.... been working in the Access mode for too long.
Sep 24 '12 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Igor | last post by:
Hi everyone! I have a program written on C# that works with Microsoft Excel application. I built it to work with Excel 2000. With runtime objects I created assemblies to connect to Excel....
4
by: Kevin R. | last post by:
Greetings, I have the following code that attempts to download an excel file: System.Web.HttpContext.Current.Response.ContentType = "application/vnd.ms-excel"; ...
6
by: BaWork | last post by:
I have the following to insert a new record: <% .. Set Conn = Server.CreateObject("ADODB.Connection") Conn.Open "DSN=qqqqq;" SQLStmt = "INSERT INTO tbl_qqqqqq (main_cat, cat_fee, fee_amount)...
4
by: leaf0209 | last post by:
Hi, I am new to this forum and have been troubled by this problem for the past few days. I would appreciate if someone would take a look and help me out. I am using vb express 2005 edition... ...
0
by: Anish G | last post by:
Hi All, I am getting the below given error while running my application in live server. In my local machine, its working fine. Please help me as it is very urgent for me. Exception from...
3
by: DontB3 | last post by:
Hi, I'm new in this forum, and i hope someone can help. I'm creating an automatic application that transfer a database from Access -> DBF -> Oracle. When My App try to execute Insert SQL...
2
by: LadyRed2 | last post by:
Hello, I am new to Excel and SQL server, so please be patient with me. I have written code with the help of others to update a table in a sql database from an excel form. The connection code...
3
by: pedalpete | last post by:
I'm getting a "missing ; before statement" error in javacript I'm surprised i wasn't able to find anything about this on this site. I am not sure why I'm getting this error, everything looks...
0
by: 362315 | last post by:
I am receiving the following error: Microsoft Visual Basic Run-Time error '2147467259 (80004005)': The microsoft jet database engine cannot open the file. It is already opened exclusively by...
4
by: EmilyA | last post by:
Hi! I'm not that good at programming, so I was wondering if anyone could tell me why I'm getting an unreachable statement error for lines 18, 35, 68, and 86. import java.util.ArrayList; ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.