VBA- is it possible to set condition based on traffic lights system ( Green light, red light yellow light etc) on a table with VBA?

kidult7

New Member
Joined
Jan 11, 2021
Messages
9
Office Version
  1. 365
Platform
  1. Windows
Hi, can VBA recognize the icon set on a table based off the light of the icon set?

I have a table that was already conditionally formatted with traffic light system based on certain creteria ( Red, Yellow or Red).
Now I would like to set a loop condition based on the traffic light off the table, is it feasible?

i.e the conditions are the following:
If traffic light is green, then corresponding cell in particular Column AJ is "N";
if traffic light is Red or Yellow, then corresponding cell in particular Column AJ is "Y"

Otherwise, "N"


Will using the below be feasible to set up with the condition at VBA?
xlIconGreenTrafficLight
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
You have to specific by what you meant by icon. Please click Xl2BB icon and install AddIn so that you can use to copy and paste how your worksheet looks like. This way will help others to understand better.
 
Upvote 0
test (1).xlsm
ABFSTUVWXAJ
3Unit of MeasureNov 2020Dec 2020Q1 2021Feb 2021Mar 2021Q2 2021Check (Y/N)
4M>=%10000%100%100%100%100%100%N
5M>=%100%100%97%100%100%100%N
6M>=%100%100%100%100%100%100%N
7M<=%0%14%13%22%20%18%Y
8M<=%0%50%0%0%0%0%N
9M<=%0%0%0%0%0%0%Y
10M<=%NA0%0%0%0%0%Y
Yellow & Red
Cells with Conditional Formatting
CellConditionCell FormatStop If True
S4:AH6Other TypeIcon setNO
S7:AH7Other TypeIcon setNO
S8:AH8Other TypeIcon setNO
S9:AH9Other TypeIcon setNO
S10:AH10Other TypeIcon setNO
 

Attachments

  • Capture.PNG
    Capture.PNG
    16.3 KB · Views: 29
Upvote 0
the code does not show the traffic light icon, I have attached an image for an reference.
Again, is it possible to set condition based on the icon set of the colour based on the table from VBA?


Thank you
 
Upvote 0
to be more specific, I have included my drafted code below, but it doesn't seem to work:


If UCase(ws.Cells(row, "B").Value) = "M" Then
If ws.Cells(row, locate_month.Column) = "" Then
ws.Cells(row, Check.Column) = "N"
ElseIf ws.Cells(row, locate_month.Column) = "N/A" Then
ws.Cells(row, Check.Column) = "N"
ElseIf ws.Cells(row, locate_month.Column).FormatCondition(1).Icon = xlIconGreenTrafficLight Then
ws.Cells(row, Check.Column) = "N"

ElseIf ws.Cells(row, lastmonth.Column).FormatCondition(1).Icon = xlIconRedTrafficLight Then
ws.Cells(row, Check.Column) = "Y"
 
Upvote 0
Why not just use Conditional Formatting instead of using VBA? Do you want something similar to this?

 
Upvote 0
the spreadsheet have been set with the conditional formatting based on the values with the icon set already as my imagine attached above Now I would like to set up a vba to looked up the the colour of the icon set for other work.. I need to make it dynamic to make it able to look at different columns/month just want to see if that’s feasible
 
Upvote 0
the spreadsheet have been set with the conditional formatting based on the values with the icon set already as my imagine attached above Now I would like to set up a vba to looked up the the colour of the icon set for other work.. I need to make it dynamic to make it able to look at different columns/month just want to see if that’s feasible
Now I think I understood what you were trying to achieve.

I believe it is possible. I don't know the correct syntax since never done it before. Why not just read the cell value instead as reference instead of the icon criteria or state?
 
Upvote 0
Because the condition varies from each row and hence preset the conditional formatting already . Now I just want to filter out those that need attention of ( red or yellow ) from the icon traffic light
 
Upvote 0
Because the condition varies from each row and hence preset the conditional formatting already . Now I just want to filter out those that need attention of ( red or yellow ) from the icon traffic light
I found out that your xlIconGreenTrafficLight is not for the icon you used. That xlIconGreenTrafficLight is for traffic light with square box

You can get the xlIcon numeration using command below for example

Debug.Print ws.Range("T4").FormatConditions(1).IconCriteria(1).Icon

Note:
ws is just the worksheet I defined
For traffic light with 3 colors, the IconCriteria index would be 1, 2, and 3

So you can have something like this

VBA Code:
If ws.Range("T4").FormatConditions(1).IconCriteria(3).Icon = xlIconGreenTrafficLight Then
    ' your code here
End If

IconCriteria(3) would be have enumeration 14 (xlIconGreenTrafficLight) for those square box traffic light
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,184
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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