+ Reply to Thread
Results 1 to 3 of 3

Macro for Borders and Colouring

  1. #1
    Forum Contributor
    Join Date
    03-30-2010
    Location
    Washington DC
    MS-Off Ver
    Excel 2007
    Posts
    458

    Macro for Borders and Colouring

    Hello everyone. I wanted to add some finishing touches to an automation project I have been working on, I recently recorded a macro which adds colors and fonts and borders and so fourth to a worksheet. Is there a better way to code this. It works perfectly fine but I was hoping for something cleaner and tighter. Thanks


    Please Login or Register  to view this content.

  2. #2
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: Macro for Borders and Colouring

    Hi AnthonyWB,
    You could replace "select" with "With" to speed things up by not needing to select them

    "
    Please Login or Register  to view this content.
    If the solution helped please donate to RSPCA

    Site worth visiting: Rabbitohs

  3. #3
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Macro for Borders and Colouring

    The "Bloat" that comes from recorded code is worst of all in the area of cell formatting. The best time to edit the code is immediately after you record it when what you changed in the cell is freshest in your mind. Any code that refers to parameters you didn't set are unnecessary and can deleted, frequently leaving only a single line of code in place of the 10-15 lines that got recorded.

    Here I tried to guess at which settings represented "defaults" and removed all of those. Along with Pike's removal of selecting this greatly increases the efficiency of your code.
    Please Login or Register  to view this content.

    Just something to look at...I may have taken too much out, which is why the best time to edit is right after recording. You would know the only thing you did was add a TintShade so you would know all the rest was dross.


    TIP: When editing border code, xlContinuous is the default linestyle, so just setting the weight will set that as well.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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