+ Reply to Thread
Results 1 to 9 of 9

Can this code be tidied up? Macro recorder appears to need some organizational skills

  1. #1
    Valued Forum Contributor
    Join Date
    04-11-2006
    MS-Off Ver
    2007
    Posts
    438

    Can this code be tidied up? Macro recorder appears to need some organizational skills

    I used macro recorder, and this code was the result. Is there a way to shorten this code up? The more I use macro recorder, the more I'm beginning to realize that the code generated from macro recorder can be very sloppy.

    By seeing you all work your magic, I can analysis what you did, and hopefully start shortening these myself


    Please Login or Register  to view this content.
    Last edited by duugg; 06-18-2009 at 09:56 AM.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Can this code be tidied up? Macro recorder appears to need some organizational sk

    Hello duugg,

    It would help to know what you are doing. Part of the code applies borders to the selected cells and the other part formats column "C" and then selects "C1". What to you want to do exactly?
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Can this code be tidied up? Macro recorder appears to need some organizational sk

    Select or Selection is seldom needed. http://www.tushar-mehta.com/excel/vb...acro_recorder/

  4. #4
    Valued Forum Contributor
    Join Date
    04-11-2006
    MS-Off Ver
    2007
    Posts
    438

    Re: Can this code be tidied up? Macro recorder appears to need some organizational sk

    Basically I'm trying to figure out how you guys figure this stuff out.

    A lot there seems to be extra nonsense. It would seem that if you just left a lot of the extra code out, it would default to it anyway. For example, instead of writing ALL this code out to fill an inside and outline border with the same formatting like this..

    Please Login or Register  to view this content.
    I would think it would make more sense to say it more efficiently...I know this code is wrong, but something to this effect...

    Please Login or Register  to view this content.
    Is there an equivalent to the above "guessed" code?

  5. #5
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Can this code be tidied up? Macro recorder appears to need some organizational sk

    Perhaps the BorderAround method - have a look at Help. That said, I think it would only do outside borders.
    Last edited by StephenR; 06-10-2009 at 02:56 PM.

  6. #6
    Valued Forum Contributor
    Join Date
    04-11-2006
    MS-Off Ver
    2007
    Posts
    438

    Re: Can this code be tidied up? Macro recorder appears to need some organizational sk

    How about something like

    Please Login or Register  to view this content.
    I have the "thought" right, but I know I probably have the syntax wrong..is there a way to combine this?

    Thanks

  7. #7
    Forum Contributor
    Join Date
    02-23-2006
    Location
    Near London, England
    MS-Off Ver
    Office 2003
    Posts
    770

    Re: Can this code be tidied up? Macro recorder appears to need some organizational sk

    As far as I am aware 'With' only operates on single objects / collections at a time, so you are unable to combine the borders within the 'With' statement.
    The macro recorder, whilst giving you the 'idea' of what you want to right is not, as you have found, particularly efficient. For one thing it will never use an array, or loops, both of which could be used to 'condense' this code.
    However what you can do if you need to apply the same settings to mulitple objects is something like this:

    Please Login or Register  to view this content.
    If you find the response helpful please click the scales in the blue bar above and rate it
    If you don't like the response, don't bother with the scales, they are not for you

  8. #8
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Can this code be tidied up? Macro recorder appears to need some organizational sk

    You can replace your Borders code with:
    Please Login or Register  to view this content.
    Remember what the dormouse said
    Feed your head

  9. #9
    Valued Forum Contributor
    Join Date
    04-11-2006
    MS-Off Ver
    2007
    Posts
    438

    Re: Can this code be tidied up? Macro recorder appears to need some organizational sk

    Thanks to both,

    Romper, I used your code first because it was shorter, and it worked perfectly.

    Thanks!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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