Finding % based on conditional format dates

gulonraid

New Member
Joined
Apr 13, 2016
Messages
12
Good morning,

I am building a training tracker for work. I figured out how to use the conditional formatting to highlight when training will be due based on expiration dates. What I would like to do it have it show a % next to a persons name based on their row of training. So if a CBT date goes red, it would lower the %. I have attached the excel doc to show what it currently looks like.
Tracker_Snippit.PNG
 
No, this code updates column B as data is updated.
So it is designed to work as data is being entered.
If you want it do run against all pre-populated data, you would need another Macro to do that, that is very similar.

Here is the version that you can manually run on existing data:
VBA Code:
Sub InitialRun()

    Dim sc As Long
    Dim ec As Long
    Dim ccode As Double
    Dim lr As Long
    Dim rng As Range
    Dim r As Long
    Dim c As Long
    Dim ctr As Long

'***Specify starting and ending column numbers in watched range
    sc = 4  '(column D)
    ec = 15 '(column O)
    
'***Specify color code
    ccode = 10285055
    
    Application.ScreenUpdating = False
    
'   Find last row in column A with data
    lr = Cells(Rows.Count, "A").End(xlUp).Row
    
'   Loop through all rows starting in row 5
    For r = 5 To lr
'   Loop through columns to get count
        For c = sc To ec
'           Add to counter if cell matches color code
            If Cells(r, c).DisplayFormat.Interior.Color = ccode Then
                ctr = ctr + 1
            End If
        Next c
'       Update column B with percentage
        Cells(r, "B").Value = ctr / (ec - sc + 1)
    Next r
    
    Application.ScreenUpdating = True
    
End Sub
So, if you have existing data, but you may also be making changes to it, and you want the calculation to update dynamically, you would use both codes.
 
Upvote 0

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
No, this code updates column B as data is updated.
So it is designed to work as data is being entered.
If you want it do run against all pre-populated data, you would need another Macro to do that, that is very similar.

Here is the version that you can manually run on existing data:
VBA Code:
Sub InitialRun()

    Dim sc As Long
    Dim ec As Long
    Dim ccode As Double
    Dim lr As Long
    Dim rng As Range
    Dim r As Long
    Dim c As Long
    Dim ctr As Long

'***Specify starting and ending column numbers in watched range
    sc = 4  '(column D)
    ec = 15 '(column O)
   
'***Specify color code
    ccode = 10285055
   
    Application.ScreenUpdating = False
   
'   Find last row in column A with data
    lr = Cells(Rows.Count, "A").End(xlUp).Row
   
'   Loop through all rows starting in row 5
    For r = 5 To lr
'   Loop through columns to get count
        For c = sc To ec
'           Add to counter if cell matches color code
            If Cells(r, c).DisplayFormat.Interior.Color = ccode Then
                ctr = ctr + 1
            End If
        Next c
'       Update column B with percentage
        Cells(r, "B").Value = ctr / (ec - sc + 1)
    Next r
   
    Application.ScreenUpdating = True
   
End Sub
So, if you have existing data, but you may also be making changes to it, and you want the calculation to update dynamically, you would use both codes.
Awesome! Thank you so much it worked like a charm!!
 
Upvote 0
Joe4, I had one more favor since you were so helpful. How would I change/add an extra VBA code if I wanted to do %s for each individual training column. I have attached a picture as the reference.
I would like to do it so it tracks all the green in that specific column and pulls a % for that based on current dates and future dates like it does on each side.
 

Attachments

  • column_snippet.PNG
    column_snippet.PNG
    68.2 KB · Views: 5
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,264
Members
449,075
Latest member
staticfluids

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