Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA Color code

Status
Not open for further replies.

zebra99

Technical User
Sep 19, 2008
14
US
How would you write VBA code to complete the following.

If any of the previous 2 cells were yellow then orange
If any of the previous 2 cells were orange then red
If any of the previous 5 cells were red then purple
If any of the previous 5 cells were purple then purple

Thanks in advance!
 
Hi,

What have you tried so far? Please post your code.

Skip,
[glasses]Don't let the Diatribe...
talk you to death![tongue]

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
I have not tried anything, I do not know how to write VB code, hence the reason I posted.
 



You have received help on sevreral previous occasions, so you ought to have some idea where to start.

Take a stab at it. This is not a coding service; it is for TIPS. Put some of your own sweat into this, okay?

Skip,
[glasses]Don't let the Diatribe...
talk you to death![tongue]

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Hi zebra99. What you are asking about has really little to do with the technicalities of coding. It has to do with logic. One route, which you have already have examples of (in your previous threads), is the use of Select Case.

Select Case is a logic routine (one of many), and that is precisely what you are trying to do...logic. You are testing conditions, which is what logic statements DO.

Try doing something yourself, and if you have problems please post what you are having problems with.

How would you write VBA code to complete the following.

If any of the previous 2 cells were yellow then orange
If any of the previous 2 cells were orange then red
If any of the previous 5 cells were red then purple
If any of the previous 5 cells were purple then purple


Answer: by writing the appropriate logic statement(s).

As a hint/suggestion, try writing out the logic in full. Yourself. No code at first, just the precise, exact logic required to do what you want to do. Think it out. Then write it out. Kind of like this:

1. get the color of EACH of the previous 5 cells
2. if any are RED...make the RED one purple

and right there is a logic issue, that you MUST think about/deal with. WHAT - precisely is the logic? If ONE of the 5 is red, make it purple, but what if THREE are red...do you make all of them purple? I am assuming so, BUT...you must explicitly state that logic. MUST. Do you see what I mean? This makes #2 above actually...

2. if any are RED, make ALL of them purple.

That is logic. The coding itself is not particularly difficult, it is the thinking that is hard.

3. if none are red, test to see if any are purple.

4. if any are purple, do nothing

5. if NONE are red OR purple, test the last TWO cells

6. if any are yellow....and so on.

So think about it, try coding something yourself (and again a hint would be Select Case and possibly some IF...THEN logic), and if you have a specific question, ask.

We are not going to code something like:

How would you write VBA code to complete the following.

for you.

Gerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top