# Filling colors in random shapes

1. ## Filling colors in random shapes

There are four transparent shapes on the worksheet myBox1, myBox2, myBox3 and myBox4

I want to fill yellow color in random shapes based on values in H4 and I4.
In the attached sample attachment, H4 value is M3. So except the box corresponding to M3, any two of the remaining boxes (1,2 or 4) should be filled with yellow color. Any two becuase, value of I4 is 2.

Another example:
Lets say H4 value is M2 and I4 value is 1 then
any one box should be filled with yellow color except the box corresponding to M2

The logic what I thought is:
I would have random numbers to the left of every box (marked in red in the attachment)
value in H4 would depend who will get a negative random number
From the remaining, check the two maximum numbers with the LARGE function and identify which box to fill

Challenge:
I have tried different ways to do this. However, not getting the syntax right to identify the box. Once the boxes are identified, it will be easier to fill.

2. ## Re: Filling colors in random shapes

Hi freeofcost,
maybe so
``Please Login or Register  to view this content.``

3. ## Re: Filling colors in random shapes

You are simply genius... It will take some time for me to understand the code. Let me have a close look at it. Meanwhile, I have ask something
I see that you have worked on my logic to create a random number and pick 1 or 2 LARGE numbers out of the 3 selection. I failed in syntax.
Do you think my logic is efficient enough or is there a better way to do it?

Also I did not understand the exclamation mark after hide1 in line 2 (hide1!)
and the ampersand mark after i in line 3 (i&)
It will be easier for me to comprehend if I understand the reason for above two statements.

Thank you

4. ## Re: Filling colors in random shapes

this is the abbreviations of variables (& means Long, ! - Single, # - Double, % - Integer, @ - Currency)
eg Dim x! is the same as Dim x As Single

\$ - As String

5. ## Re: Filling colors in random shapes

Originally Posted by nilem
this is the abbreviations of variables
Oh! I never came across something like this. Will keep it in mind.

Sorry if I try to sound stupid.... I wish to understand r(1, 3)... I understood 'r' is the every single element of the defined range (A4,D4,A6,D6). I am confused because not matter the value for Range("I4").Value is 1 or 2, the r(1, 3) always remain constant.
I am trying to understand this because:
1. When the cell is colored yellow, i want to set visibility of the shape object over the yellow cell to False temporarily which will be set to True later by another macro
2. do some activity to change the set random values

6. ## Re: Filling colors in random shapes

maybe something like
``Please Login or Register  to view this content.``
``Please Login or Register  to view this content.``

7. ## Re: Filling colors in random shapes

Got it !
I tried doing the reverse order of TopLeftCell but I was doing it in combination with Application.Caller
understood the row/column index too

Thank you !

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

#### 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