Solved

VBA Syntax

Posted on 2011-02-10
6
298 Views
Last Modified: 2012-05-11
ActiveCell.Offset(i, 5).Formula = ("=Text(" & ActiveCell.Offset(i, 0).Value & "," & ""mmddyy"" & ")")

I have the following line . I get an error highlighting mmddyy and it says "Expected )"

How can I correct this?
0
Comment
Question by:awesomejohn19
  • 3
  • 2
6 Comments
 
LVL 30

Accepted Solution

by:
SiddharthRout earned 500 total points
ID: 34864539
Try this

ActiveCell.Offset(i, 5).Formula = "=Text(" & _
                                  ActiveCell.Offset(i, 0).Value & _
                                  "," & _
                                  """" & _
                                  "mmddyy" & _
                                  """" & _
                                  ")"

Open in new window


Sid
0
 
LVL 37

Expert Comment

by:TommySzalapski
ID: 34864705
You need to use double quotes for every quote mark that you actually want. So your line needs to be
ActiveCell.Offset(i, 5).Formula = "=Text(" & ActiveCell.Offset(i, 0).Value & ",""mmddyy"")"
0
 
LVL 81

Expert Comment

by:byundt
ID: 34864718
ActiveCell.Offset(i, 5).Formula = "=Text(" & ActiveCell.Offset(i, 0).Value & "," & """mmddyy""" & ")"

You need to use three double quotes before and after mmddyy to get one double quote to appear in the actual formula
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 37

Expert Comment

by:TommySzalapski
ID: 34864740
You can split them all apart separately as in Sid's solution, but this should not be needed.
By double quotes, I meant two double quotes (or double double quotes). Anyway = "AA""A" will translate to AA"A.
0
 
LVL 30

Expert Comment

by:SiddharthRout
ID: 34864754
You are right Tommy. I deliberately split them so that OP can understand every part of it. :)

Sid
0
 
LVL 30

Expert Comment

by:SiddharthRout
ID: 34864797
awesomejohn19: Thank you for the points but I feel the points should have been equally distributes amongst us :)

Sid
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

919 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now