+ Reply to Thread
Results 1 to 14 of 14

Macro recorded with errors in Excel VBA

  1. #1
    Registered User
    Join Date
    03-26-2008
    Posts
    44

    Macro recorded with errors in Excel VBA

    I am recording a macro to automatically generate the lines of code. After I start the macro and stopped recording, I check the code. Immediately, I receive a "Syntax Error".


    This was a recorded macro, why would it generate a wrong code?

    The code below is exactly how it was recorded.

    I have Excel 2016 in WindoWs 10.

    Thank you
    Please Login or Register  to view this content.
    Last edited by gtg430i; 02-24-2019 at 12:08 AM.

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2404 Win 11 Home 64 Bit
    Posts
    23,865

    Re: Macro recorded with errors in Excel VBA

    Your post does not comply with Rule 2 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.

    Click on Edit to open your thread, then 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

    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 6)
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: Macro recorded with errors in Excel VBA

    This makes absolutely no sense.

    Explain the steps you took to get to this result.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  4. #4
    Registered User
    Join Date
    03-26-2008
    Posts
    44

    Re: Macro recorded with errors in Excel VBA

    Hello - Yes totally agree. Something strange is happening.

    I am simply recording a macro - The macro selects a table and filter the data based on certain criteria. My concern is that the macro is recording with a syntax error exactly as the code I posted. If you attempt to run the code again, it throws an error. I am just confused why the macro generates a bad code.

    Please see attached snapshot of recorded macro.MacroError.jpg

  5. #5
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: Macro recorded with errors in Excel VBA

    Can you post an example file with desensitized data.

    Explain clearly the steps you take.

  6. #6
    Registered User
    Join Date
    03-26-2008
    Posts
    44

    Re: Macro recorded with errors in Excel VBA

    I have attached a sample file. Please check recorded macro.

    I simply selected cell A1, scrolled to right and then down, then filtered column T for "BUY". Stopped macro recording.

    Thanks
    Attached Files Attached Files

  7. #7
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: Macro recorded with errors in Excel VBA

    This should do the trick.
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    03-26-2008
    Posts
    44

    Re: Macro recorded with errors in Excel VBA

    Hello - I am not looking for trick. I am very concerned to why would a macro record with a wrong syntax.

    Any thoughts?

    Thanks

  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,373

    Re: Macro recorded with errors in Excel VBA

    When I record those actions for the first part, I get this:

    Please Login or Register  to view this content.
    It looks as though a Replace All has removed the word "Selection". I can't imagine what would cause that. Have you edited this code, or edited earlier code and used a Replace All?
    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


  10. #10
    Registered User
    Join Date
    03-26-2008
    Posts
    44

    Re: Macro recorded with errors in Excel VBA

    The only thing is that this is a new computer I am working on with a new Office. Everything works fine if I use a different computer. I am not sure...

  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,373

    Re: Macro recorded with errors in Excel VBA

    What keystrokes did you use when you recorded that macro? I can't repeat it.

  12. #12
    Registered User
    Join Date
    03-26-2008
    Posts
    44

    Re: Macro recorded with errors in Excel VBA

    control+shift + right arrow/down arrow

  13. #13
    Registered User
    Join Date
    08-27-2016
    Location
    San Diego
    MS-Off Ver
    2016
    Posts
    6

    Re: Macro recorded with errors in Excel VBA

    I am having this same exact problem. Did anyone ever find a solution for this?

  14. #14
    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,373

    Re: Macro recorded with errors in Excel VBA

    Administrative Note:

    Welcome to the forum.

    We are happy to help, however whilst you feel your request is similar to this thread, experience has shown that things soon get confusing when answers refer to particular cells/ranges/sheets which are unique to your post and not relevant to the original.

    Please see Forum Rule #4 about hijacking and start a new thread for your query.

    If you are not familiar with how to start a new thread see the FAQ: How to start a new thread

+ 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. Simple Excel Recorded Macro Has Syntax Errors
    By MotorCityCanuck in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-12-2018, 04:54 PM
  2. Recorded Macro Errors...
    By Will03 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-03-2014, 02:48 PM
  3. [SOLVED] Need to take off Recorded Macro which minimizes the Excel program
    By cesarmontoya in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-19-2013, 02:30 PM
  4. [SOLVED] Recorded Pivot Table Macro Doesn't Do What I Recorded!
    By diakonos1984 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-26-2013, 11:01 AM
  5. [SOLVED] excel 2007 chart macro graphs data only from sheet on which macro was recorded
    By JW1028 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-19-2013, 06:33 PM
  6. Recorded macro that creates buttons errors when I run it
    By cklein in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 07-09-2012, 06:24 PM
  7. Excel VBA error-recorded a macro to sort
    By Leena in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-13-2005, 11:06 AM

Tags for this Thread

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