PDA

View Full Version : (VBA) Conditionnal formatting with multiple conditions



Frederikvh
06-17-2014, 01:30 AM
Hey everyone, I'm turning to you all because I can't figure it out myself for the life of me.
I've scoured the forum, but even though my thread title might say otherwise, I can't find anything that can get me where I want to get :)
For the sake of argument, let's say I have a worksheet with 2 columns: column F with numbers in it, column H with text in it.
For example
F H
100 P4
200 P4
800 P2
430 P3

There is no order in how the numbers are defined, and the amount of rows varies from time to time.

What I would to accomplish is the following (in some random mumbo-jumo pseudo-code style thing):

Case H2=P4
case F2<1200
range = yellow background
case F2<800
range = red background
Case H2=P3
case F2<480
range = yellow background
case F2<320
range = red background
Case H2=P2
case F2<240
range = yellow background
case F2<160
range = red background
Case H2=P1
case F2<120
range = yellow background
case F2<60
range = red background

With range, I mean the first cell in that row, untill the last cell in that row that isn't empty.
The first row in the document can be ignored because that's just the column headers.

The above would have to be repeated for each row in the document..

Honestly, I have no idea where to start. I have some experience in coding but this VBA thing seems beyond me :p

Here's to hoping you can point me in the right direction!

Kind regards

Simon Lloyd
06-17-2014, 04:16 AM
Try:
Select Case
Case H2=P4 AND F2<1200 AND F2>800

Thats about as much help as i can give without seeing the structure of your data.....etc

p45cal
06-17-2014, 04:45 AM
I suspect you can do this with conditional formatting (what version of Excel are you using?)
As Simon says we'd need to see a little more; could you attach a sample file (you may need to have posted here 5 times before you can - I'm not sure - if so, perhaps a link to a file-sharing site (but this site won't let you post links until you've posted 5 times too! but you can remove the http:// bit and it should accept it)).

Frederikvh
06-17-2014, 05:43 AM
Using the conventional way to apply conditional formatting worked for about 3 to 4 rules, after that they began to overwrite eachother in a non-sensical manner :)
As for the example of my data, I'd have to scrap a few things because it contains some company specific data and they're not to keen on data leaks.

As for the progress itself, I've made some and will definately post back with the results!