VBA - highlight consecutive

mahmed1

Well-known Member
Joined
Mar 28, 2009
Messages
2,302
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hi, I am really hoping someone can help me with some VBA code that can help me with this as ive had no luck with a previous thread

I have a row of data

Say B6 (I have % target variable) ie >70%
In D6 (I have consecutive day target 3)
In E6 (to last column as data will get added in column and each day) i have the data

What i want the VBA code to do is if the value from E6 to last column is
More than target % and has remained like that for more than or = to consecutive day target then highlight that value red colour...

Eg if the values are
69, 67,68,71,70,71 (highlight 71), 77, (highlight 77), 55,67,78,78,60,61,70,71,77 (highlight 77), 78 (highlight 78), 75 (highlight 75)

I hope this makes sense and really hope someone can help me

The other thing i have is in row E3 i have the dates listed..... I want to have a macro that filters by days
So say i had a macro to only display mondays data (i can loop through to hide other columns and just show mondays columns) and then what if want the highlight code to is still check for the condition but look at the visible cells

So only look at the visible columns from E3 and look at the condition and highlight

Please can someone help me with this

Thank You
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Not sure about the second part but for the first part, does this Conditional Formatting do what you want?

20 10 20.xlsm
ABCDEFGHIJKLMNOPQRSTUVWXYZ
6703696768717071775567787860617071777875
750780706078789080205050505050505050606562701015
8482504847405459396164346850586050316054624367
CF Consecutive
Cells with Conditional Formatting
CellConditionCell FormatStop If True
E6:Z10Expression=AND(COLUMNS($E:E)>=$D6,E6<>"",MIN(OFFSET(E6,,,,-$D6))>=$B6)textNO
 
Upvote 0
Wow - i’ll test this and give it a go when i get access to excel

Based on your example shown that looks perfect - Your amazing and thank you...

Re second Part - How Can i amend this formula where if i had a macro to hide columns ie display every mondays then the formula to work exactly same way but instead look at visible cells (This way i can filter Mondays, Tuesdays via code and still have conditional formatting work)
 
Upvote 0
Hi Peter - I tested the formula and it worked perfect to check against greater than or = column C target - I changed to > than rather than >= but works fine

I need to add a couple of variations to this formula where i check to see if the value is < than column C target as some metrics are bad if it goes down but if i change to < it dont work

(My column started at F and days to check were col D as is in your example and value to compare against in C)


The couple of variations i need to apply are 1 to check if the value is less than target
eg =AND(COLUMNS($F:F)>=$D11,F11<>"",MIN(OFFSET(F11,,,,-$D11))
<$C11)

and 2 = check if the value < than target in column B or > target in column C (as 1 or 2 metrics needs to check to see if the value is either lower than lower bound and higher than upper bound
=AND(COLUMNS($F:F)>=$D11,F11<>"",OR(MIN(OFFSET(F11,,,,-$D11))<$B11,MIN(OFFSET(F11,,,,-$D11))>$C11))

I tried tweaking the above to formulas like listed above without any success :(
 
Upvote 0
Can you give us some simple sample data, manually coloured, with XL2BB & explain in relation to that sample data?
I can't follow for sure what you are saying and giving formulas that don't work doesn't actually help.
 
Upvote 0
Hi does the image below help

For metric 1 im checking to see if the value is less than -20 or > 20 and consec days >=3

Metrics 2 - 3 im checking to see > 500 and 60 and consec days >=3

Metric 4-5 im checking to see < 90 and consec days >=3

There will me many metrics so i can apply the relevant conditions to the that row criteria eg if another metric added was same as metric 1 - ill just apply the rule the same as metric 1

Hopefully this explains it better (The formula you provided works perfect for > target and >= consec days)

B, C, D, E, F

1603185054912.png
 
Upvote 0
Hiya

Does this help

Ive put the level of conditions on there and how it should format

TargetConsecutive DaysMetrics28/09/202029/09/202030/09/202001/10/202002/10/202003/10/202004/10/202005/10/202006/10/202007/10/202008/10/202009/10/202010/10/2020
<-20.00%20.00%3Metric 1-21.00%-21.00%-21.00%-21.00%25.00%15.00%15.00%15.00%-21.00%-21.00%90.00%90.00%90.00%
>5003Metric 2500500501501520520520500500500501501501
<90.00%3Metric 490.00%90.00%90.00%85.00%85.00%85.00%85.00%85.00%90.00%85.00%84.00%84.00%84.00%
 
Upvote 0
TriggerPoints Test.xlsx
ABCDEFGHIJKLMNOPQR
1
2
3
4
5TargetConsecutive DaysMetrics28/09/202029/09/202030/09/202001/10/202002/10/202003/10/202004/10/202005/10/202006/10/202007/10/202008/10/202009/10/202010/10/2020
6<-20.00%20.00%3Metric 1-21.00%-21.00%-21.00%-21.00%25.00%15.00%15.00%15.00%-21.00%-21.00%90.00%90.00%90.00%
7
8>5003Metric 2500500501501520520520500500500501501501
9
10<90.00%3Metric 490.00%90.00%90.00%85.00%85.00%85.00%85.00%85.00%90.00%85.00%84.00%84.00%84.00%
11
Sheet1
Cell Formulas
RangeFormula
G5:R5G5=F5+1
 
Upvote 0

Forum statistics

Threads
1,214,832
Messages
6,121,853
Members
449,051
Latest member
excelquestion515

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top