+ Reply to Thread
Results 1 to 4 of 4

syntax error in vba formula

  1. #1
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    syntax error in vba formula

    i have the following code that works inside a sheet. now need to adapt that formula so that is runs inside VBA

    Please Login or Register  to view this content.
    also have the same need for this formula as well

    Please Login or Register  to view this content.
    sadly i had the code working for ifna but excel crashed and didn't recover the update code.

    any help on quote marks in formulas would be helpful

  2. #2
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,883

    Re: syntax error in vba formula

    Double quotes should be nested inside double quote.
    Depending on use, you should also change relative/absolute reference for range.
    Ex:
    Please Login or Register  to view this content.
    ?Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something.?
    ― Robert A. Heinlein

  3. #3
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,408

    Re: syntax error in vba formula

    Quote Originally Posted by dmcgov View Post
    any help on quote marks in formulas would be helpful
    Text constants in VB are delineated by quote marks surrounding the text. If you tried to put a quote mark inside of the text like this...

    "LeadInText"AfterText"

    VB cannot tell if that middle quote mark was meant to end the text constant or if it was meant as a single quote mark character. I know it is fairly obvious as to intent by looking at it, but VB's parser has rigid rules it follows when interpreting code lines. To tell VB to treat that middle quote mark as a character instead of a text delimiter, you simply double it up like this...

    "LeadInText""AfterText"

    Now where some confusion comes in is when your text starts or ends with a quote mark character. But, if you remember this...

    "LeadInText""AfterText"

    then the rest is easy. If your text starts with a quote mark character, then there is no lead-in text, so removing it leaves this...

    """AfterText"

    The first quote is the text constant delimiter and the next two is the quote mark character as VB sees it. You could do the same for a quote mark character at the end of the text constant, simply remove the text after it...

    "LeadInText"""

    And finally, if your text just consist of a single quote mark (usually to be concatenated with a variable), just remove the lead-in and after text leaving simply this...

    """"

  4. #4
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: syntax error in vba formula

    many thanks Rick for that detailed explanation. very helpful!

    now lets see if i can apply this new knowledge.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Syntax error for If then Else formula
    By robert26 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-13-2019, 02:53 PM
  2. [SOLVED] syntax of array vba formula-error
    By pnnaik in forum Excel General
    Replies: 3
    Last Post: 04-01-2018, 01:55 PM
  3. [SOLVED] VBA - putting a formula in cells but its got a syntax error please help!! :-)
    By LauraWork in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-27-2013, 08:06 AM
  4. [SOLVED] ActiveCell.Formula Syntax Error
    By Leipzig in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-24-2013, 12:18 PM
  5. Complex Formula Syntax error
    By Cyd44 in forum Excel General
    Replies: 2
    Last Post: 07-01-2012, 10:35 AM
  6. activesheet.cells(i, 3).formula SYNTAX ERROR
    By smartphreak in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 03-07-2012, 06:51 AM
  7. Error with formula syntax
    By menefist in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-28-2005, 03:42 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1