+ Reply to Thread
Results 1 to 11 of 11

Compiile error: Expected: expression

  1. #1
    Registered User
    Join Date
    05-02-2007
    Posts
    8

    Smile Compiile error: Expected: expression

    Dear Friends need your help

    I am getting a:
    Compiile error: Expected: expression

    for the following macro:

    Sub Macro2()
    '
    ' Macro2 Macro
    '

    '
    Range("G3:J17").AdvancedFilter
    Action:=xlFilterCopy,
    'CriteriaRange:=Range( _
    '"D1:D3"),

    Range("A1").SelectRange("A1").Select
    Range(Selection, Selection.End(xlDown)).Select
    CopyToRange:=Range("L3"), Unique:=False
    End Sub

    The error is being highlighted on the following position:
    :=x

    My second question is:
    Can one use "End Down" when the range is not known for
    List range
    and for
    Criteria range

    to do a Advance filter by changing the vba code manually ??

    Look forward for your help and thanks in advance for the same.

    Kind regards
    Roy

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,451

    Re: Compiile error: Expected: expression

    What did the code look like before you started editing it?

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    05-02-2007
    Posts
    8

    Re: Compiile error: Expected: expression

    Hello TMS

    The original, see below:

    Sub Macro2()
    '
    ' Macro5 Macro
    '

    '
    Range("G3:J17").AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=Range( _
    "D1:D3"), CopyToRange:=Range("L3"), Unique:=False
    End Sub


    Regards, Roy

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Compiile error: Expected: expression

    Roy, please take a few minutes to read the forum rules, and then edit both of your posts to add CODE tags.

    Thanks.
    Entia non sunt multiplicanda sine necessitate

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,451

    Re: Compiile error: Expected: expression

    Please use Code Tags around your code excerpts.

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    Please Login or Register  to view this content.

    Regards, TMS

  6. #6
    Registered User
    Join Date
    05-02-2007
    Posts
    8

    Re: Compiile error: Expected: expression

    Hello TMS

    Sorry for the noncompliance. I hope I have done it correct now, see below:

    Please Login or Register  to view this content.
    Thanks, Roy

  7. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,451

    Re: Compiile error: Expected: expression

    Yes, but ideally, you should edit your first post too.

    If the code is not edited, it works. I have edited it and also provide a mechanism for limiting the rows.

    What exactly are you trying to do?

    Regards, TMS

  8. #8
    Registered User
    Join Date
    05-02-2007
    Posts
    8

    Re: Compiile error: Expected: expression

    Hello TMS

    Once again thanks. I have updated as suggested, see below:

    Please Login or Register  to view this content.

    What I am trying to is extract data from a database spreadsheet which match the given criteria though a macro.
    As the CriteriaRange can vary e.g it could be once D1:D3 and in the next query D1:D100, I used the Advance Filter
    in my macro. Next I edited the stored marco by inserting CriteriaRange the End Down functionality, so that it would
    highlight all the cells belonging to the criteria range every time the number of cells involve change.

    Kind regards
    Tanoy

  9. #9
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,451

    Re: Compiile error: Expected: expression

    Maybe this then:

    Please Login or Register  to view this content.

    Regards, TMS

  10. #10
    Registered User
    Join Date
    05-02-2007
    Posts
    8

    Re: Compiile error: Expected: expression

    Thanks for your help TMS.
    Your solution works fine.

    Regards, Roy

  11. #11
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,451

    Re: Compiile error: Expected: expression

    You're welcome. Thanks for the rep.



    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save


    You may also want to consider thanking those people who helped you by clicking on the little star at the bottom left of their reply to your question.

+ 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. VBA error question (Expected expression) Application.Worksheetfunction
    By Gijsbenjezelf in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-04-2014, 12:40 PM
  2. [SOLVED] Compile Error: Expected: expression
    By Wheelie686 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-30-2013, 08:51 AM
  3. [SOLVED] Compile error: Constant expression required error when merging two Codes
    By Kezwick in forum Outlook Programming / VBA / Macros
    Replies: 8
    Last Post: 06-26-2013, 09:32 AM
  4. [SOLVED] Compile Error: Expected Expression, Syntax Error
    By gjohn282 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-20-2012, 11:28 PM
  5. Syntax Error and Compile Error: Expected Line Number or Label...
    By AnthonyWB in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-31-2011, 09:59 AM
  6. VBA compilation error : expected expression error
    By raknahs in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-21-2010, 12:57 PM
  7. [SOLVED] if isna vlookup expected expression error
    By harishankarin in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-20-2010, 04:16 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