+ Reply to Thread
Results 1 to 5 of 5

Simplify or clean a macro that sets the interior color of a non-contiguous range

  1. #1
    Registered User
    Join Date
    07-25-2008
    Location
    Bend, Oregon
    Posts
    39

    Simplify or clean a macro that sets the interior color of a non-contiguous range

    Hi folks, I’ve gotten great help here before and am hoping that you can help me again. I have a piece of code that sets the interior color of a non-contiguous range of cells to green, 35. It works but I’m sure it could be a lot cleaner, I just don’t have the experience to make it cleaner. This piece of code runs within a looping procedure that loops through several worksheets. MyWrkSht is a variable passed to the procedure that represents the worksheet name, column is a variable that represents a column number that the procedure determines is the correct column to set the interior color. So, any simplified code would need to be able to use these two variables. Thanks in advance for the help.

    Please Login or Register  to view this content.
    Last edited by TrafficGuy; 02-16-2011 at 12:08 PM. Reason: Was told to make the title more clear by the admin

  2. #2
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Simplify or clean a macro that sets the interior color of a non-contiguous range

    I don't see a pattern that you could use in a loop so other than creating an array of the row numbers and looping through that I don't see much that can be changed.

    Dom
    "May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."

    Use code tags when posting your VBA code: [code] Your code here [/code]

    Remember, saying thanks only takes a second or two. Click the little star to give some Rep if you think an answer deserves it.

  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: Simplify or clean a macro that sets the interior color of a non-contiguous range

    Not sure this is really much better than what you had originally. It's still the same number of iterations, just less lines of code, and some would find this particular syntax much harder to read.
    Please Login or Register  to view this content.
    _________________
    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!)

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

    Re: Simplify or clean a macro that sets the interior color of a non-contiguous range

    You could select the cells of interest, enter a name in the Names box (left of the formula bar), and then

    Please Login or Register  to view this content.
    Entia non sunt multiplicanda sine necessitate

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

    Re: Simplify or clean a macro that sets the interior color of a non-contiguous range

    And the points for a great example that made me chuckle today goes to: shg

+ 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