+ Reply to Thread
Results 1 to 11 of 11

Shorten VBA Code

  1. #1
    Registered User
    Join Date
    05-10-2017
    Location
    india
    MS-Off Ver
    ms 2010
    Posts
    3

    Shorten VBA Code

    Getting : Compile Error - Procedure too long.
    Please help me to shorten my VBA Code.

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by capt_rakeshshah; 05-11-2017 at 06:33 AM. Reason: To comply to Forum rules

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,607

    Re: Shorten VBA Code

    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.

    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 7)
    Ben Van Johnson

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

    Re: Shorten VBA Code

    Welcome to our forum. You obviously did not take the time to read our few forum rules. Please do so now as you have not followed at least two of them.

    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.

    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

    Also----

    Your post does not comply with Rule 8 of our Forum RULES. Do not crosspost your question on multiple forums without including links here to the other threads on other forums.

    Cross-posting is when you post the same question in other forums on the web. The last thing you want to do is waste people's time working on an issue you have already resolved elsewhere. We prefer that you not cross-post at all, but if you do (and it's unlikely to go unnoticed), you MUST provide a link (copy the url from the address bar in your browser) to the cross-post.

    Expect cross-posted questions without a link to be closed and a message will be posted by the moderator explaining why. We are here to help so help us to help you!

    Read this to understand why we ask you to do this, and then please edit your first post to include links to any and all cross-posts in any other forums (not just this site).

    This thread should not receive any responses until the OP complies with this request.
    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

  4. #4
    Forum Expert
    Join Date
    03-20-2015
    Location
    Primarily UK, sometimes NL
    MS-Off Ver
    Work: Office 365 / Home: Office 2010
    Posts
    2,405

    Re: Shorten VBA Code

    Edit: cross-posted with mod above (with similar statement), so post removed
    Regards,
    Aardigspook

    I recently started a new job so am a bit busy and may not reply quickly. Sorry - it's not personal - I will reply eventually.
    If your problem is solved, please go to 'Thread Tools' above your first post and 'Mark this Thread as Solved'.
    If you use commas as your decimal separator (1,23 instead of 1.23) then please replace commas with semi-colons in your formulae.
    You don't need to give me rep if I helped, but a thank-you is nice.

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

    Re: Shorten VBA Code

    Welcome to the forum. Unfortunately ...

    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.

    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


    It's only 471 rows and it compiles OK for me.


    The first couple of sections can be shortened like this ... you'll see the pattern:

    Please Login or Register  to view this content.

    With a little effort, it could be put in a loop

    Please Login or Register  to view this content.
    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


  6. #6
    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,419

    Re: Shorten VBA Code

    Sorry guys; didn't refresh. Same message but I thought I'd give some guidance too

  7. #7
    Registered User
    Join Date
    05-10-2017
    Location
    india
    MS-Off Ver
    ms 2010
    Posts
    3

    Re: Shorten VBA Code

    Sorry for the mistake.
    Have done necessary changes as asked to do.
    Looking for guidance from the experts.
    Thank you.

  8. #8
    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,419

    Re: Shorten VBA Code

    Thank you. Did you look at the solution I proposed? It's not the best but it will very much shorten the current code.

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

    Re: Shorten VBA Code

    OK, just looked at the code in the text file; I had assumed that it was the same as the code you included in the post. So, there are just short of 2,600 lines of code, hence the issue.

    A brief check seems to indicate a lack of consistence in the cells that are copied and pasted to. That means a loop is less practical than it might have been hoped.

    However, the edits I made to the first couple of blocks looks to halve the original code. So, if you applied that approach to the rest of the code, you'd get down to about 1,300-1,400 lines of code. That would probably be enough to allow compilation.

    If you could indicate a pattern in relation to which cells are copied and where they are pasted, it might be possible to produce a loop which would reduce the code significantly.

  10. #10
    Registered User
    Join Date
    05-10-2017
    Location
    india
    MS-Off Ver
    ms 2010
    Posts
    3

    Re: Shorten VBA Code

    Sir, With your permission would like to share the file that i am working on. My problem is with code assigned to Macro8. Thank you.
    Attached Files Attached Files

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

    Re: Shorten VBA Code

    Try this. Note that it is limited to the first 30 entries for testing purposes. As screen updating is off, it is not obvious that anything is happening, hence I have added a Debug.Print

    Please Login or Register  to view this content.

+ 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. shorten code vba
    By wildonln in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-07-2016, 03:50 PM
  2. [SOLVED] Represent (define?) a section of code with a variable (shorten long code lines)?
    By Gene@action in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-01-2016, 03:59 PM
  3. To shorten the VBA code
    By gan_xl in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-06-2014, 03:36 PM
  4. Looking to shorten VBA code
    By swhite7 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-02-2013, 06:31 PM
  5. [SOLVED] Very inefficient code because of different sizes of arrays, how do i shorten my code?
    By Brammer88 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-28-2012, 04:49 PM
  6. [SOLVED] Shorten VBA Code......!!!!
    By sagar007 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-26-2012, 08:27 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