+ Reply to Thread
Results 1 to 7 of 7

Random fill color macro

  1. #1
    Registered User
    Join Date
    10-30-2006
    Posts
    6

    Unhappy Random fill color macro

    I Googled around and cobbled a macro to generate a random fill color. I pre-select the range I want colored, and it fills that range with the supposedly random number using the RGB naming convention. It has worked very well on most of my spreadsheets except for one. In this case I have used a variety of color fills to separate different types of information - and for fun. However, it will select a color almost every time that is somewhere used on this sheet. I may have a total of 20 or so different colors - no where near the 255 x 255 x 255 = 16 million or so possibilities. I have not seen how far it will go in repeating pre-used colors but I have had it do so 10 times in a row before i quit trying. I am not using any conditional formatting on this sheet. Here is the code: '

    Please Login or Register  to view this content.
    The lines I've "remarked out" were abortive attempts to foil the color matching gremlin. I've watched the three rand variables as they are generated one by one to see if i could possibly tell that they were being generated based on previously used rgb codes already in use - but I saw nothing unusual other than the code ended up being one that has already been used on this spreadsheet.

    This is not life-threatening, but I sure am curious and willing to accept shame and remorse at overlooking something simple - if one of you can tell me what is going on. I have seen no repetitious color selecting on virgin sheets.

    Thanks in advance.

    Korndorb
    Last edited by jeffreybrown; 08-08-2013 at 07:26 PM.

  2. #2
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,525

    Re: Random fill color macro

    Hi Korndorb,

    See if using (putting) the Randomize function just beneath where you declare your variables does the trick.

    Regards,

    Robert
    ____________________________________________
    Please ensure you mark your thread as Solved once it is. Click here to see how
    If this post helps, please don't forget to say thanks by clicking the star icon in the bottom left-hand corner of my post

  3. #3
    Registered User
    Join Date
    10-30-2006
    Posts
    6

    Re: Random fill color macro

    Robert, here is my code without all the "remarked out stuff" - just the minimal code being used:

    Please Login or Register  to view this content.
    How can put the rand1 =..., rand2 = .... any closer to the variable declarations? I assume I understand your suggestion and that the rand1= etc., three statements are the "Randomize function", and that the dimension statements is where the variables are declared.

    Thanks Bob K.
    Last edited by jeffreybrown; 08-08-2013 at 07:25 PM.

  4. #4
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,525

    Re: Random fill color macro

    Hi Bob,

    Try this:

    Please Login or Register  to view this content.
    HTH

    Robert

  5. #5
    Registered User
    Join Date
    10-30-2006
    Posts
    6

    Re: Random fill color macro

    That seems to have fixed it. Thank you very much. Why did that fix it?

    Bob K

  6. #6
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,525

    Re: Random fill color macro

    Why did that fix it
    Randomize forces the Rnd function to start afresh whereas without it Rnd always starts at the same number. See here for more info.

    If you could mark the thread as closed it would be appreciated.

    Regards,

    Robert

  7. #7
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: Random fill color macro

    Hi Bob K,

    Administrative Note:
    • We would love to continue to help you with your query, but first, before we can proceed…
    • Please see Forum Rule #3 about the proper use of code tags and adjust accordingly...
    • Added for you this time, but please use them in the future…Thanks.
    HTH
    Regards, Jeff

+ 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. Fill Random Cells With a Specified Color
    By edizzi in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-02-2013, 04:04 AM
  2. [SOLVED]Fill Color (highlight cells) but not to print fill color
    By itszille in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-24-2012, 05:37 PM
  3. Macro to fill the color in particular cell
    By judethomas in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-28-2012, 04:28 AM
  4. Random Color Macro only in wanted cells
    By justh8me in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-11-2011, 05:09 PM
  5. Macro to change the Fill-Color command color
    By Ingeniero1 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-05-2010, 01:40 PM

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