+ Reply to Thread
Results 1 to 5 of 5

Syntax Error 1004

  1. #1
    Registered User
    Join Date
    06-24-2015
    Location
    Australia
    MS-Off Ver
    2013
    Posts
    8

    Syntax Error 1004

    Hi,

    I am trying to create a macro with VBA using the following formula:

    Please Login or Register  to view this content.
    When I try to run the macro it comes up with a syntax error 1004.

    If I reduce the formula to

    Please Login or Register  to view this content.
    it works fine.

    It is as though VBA can only handle up to a certain formula length.

    Could anyone help?

    Cheers
    T
    Last edited by Tip1985; 06-25-2015 at 01:11 AM.

  2. #2
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,863

    Re: Syntax Error 1004

    I could not re-create the same error (pitty you've not posted a dummy sample workbook), but just in case:
    use such formula instead, it's much shorter and less prone for errors:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    so basically, you put yout pairs matchedvalue-returnedvalue separated by comma and between each pair put semicolon. (if it's not working with your version of excel - try reversing: comma between pairs and elements in pair separated with semicolon)
    Best Regards,

    Kaper

  3. #3
    Registered User
    Join Date
    06-24-2015
    Location
    Australia
    MS-Off Ver
    2013
    Posts
    8

    Re: Syntax Error 1004

    Hi Kaper,

    Thanks for your response. I tried your formula and it doesn't return anything.

    I have attached a dummy workbook.

    Sheet 1 has your formula applied in column D.
    Sheet 2 has your formula with ; & , swapped.
    Sheet 3 has my formula.
    Sheet 4 I recorded a macro with my formula and I get a message to debug then the syntax error.

    Here is the VBA script - It highlights from ActiveCell to the end of the formula in yellow.

    Please Login or Register  to view this content.
    I am interested if you can replicate my issue.

    Cheers
    T
    Attached Files Attached Files
    Last edited by Tip1985; 06-24-2015 at 05:39 PM. Reason: To Add code tags

  4. #4
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,863

    Re: Syntax Error 1004

    Hi,

    With sample data it's obvious that my formula is wrong. So discard it.

    As the problem with the formula to be inserted by the VBA - look at front and end of sub strings you splitted thye formula ther are incomplete
    Please Login or Register  to view this content.
    so VBA could not insert such wrong formula
    Right notation could be for instance:
    Please Login or Register  to view this content.
    Having sample file available, I can propose such (sample - may be not most effective, but I hope easy to read) code to do this without formulas.

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    06-24-2015
    Location
    Australia
    MS-Off Ver
    2013
    Posts
    8

    Re: Syntax Error 1004

    Hi Kaper,

    VBA must put breaks in the formula when recording a macro. I copied your formula into VBA and it works seemlessly.

    The code you wrote also works fine. If only I could understand it.

    Thanks so much for your assistance.

+ 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. Excel macro (compile error. syntax error.) error
    By salar_younis in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-06-2014, 06:11 AM
  2. [SOLVED] Error 1004: Application-defined or object-defined error on Range(Cells(x,y)) syntax
    By winch in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-04-2013, 11:02 AM
  3. Error "run-time Error '1004': General Odbc Error
    By D4WNO77 in forum Access Tables & Databases
    Replies: 2
    Last Post: 07-16-2012, 09:55 AM
  4. Run time error 1004 syntax problem
    By 1eyedjack in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-22-2010, 04:51 AM
  5. Syntax error 1004 at ".Refresh BackgroundQuery:=False"
    By roth_georg in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-30-2008, 07:58 AM

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