VBA help! Function Case Statement and multi conditions for cell coloring

Krrrcko

New Member
Joined
Aug 7, 2014
Messages
3
Ok - I admit - I am adding two questions into one thread.:eek:

First scenario:

In column G - I have different phases. I need to calucate how many dates it's been in that phase. It's an easy formula =networkdays(O2,Today(), Holidays A1:A10). O2 is the day that it moved into that phase.

Here's the problem. There are 7 phases. And 7 different date columns based on the phase and when it moved into that phase. So for the 1st phase you use O, 2nd phase you use P, 3rd phase you use Q, etc to figure out the correct date of the phase. I didn't want to do a nested if function because they get messy and don't translate well to VBA. I decided to create a function and build a case statement. I am having issues in the code making it work with a formula as the case result. I have been able to use this for other items and it has worked well, but I can't figure out how to get this formula to work within the case statement.
Code:
Function CurrentDaysStatus(G As Range, O As Range, P As Range, Q As Range, R As Range, S As Range, T As Range, U As Range)
    Dim sCurrentDays As String
    Select Case G.Value
        Case "Intent"
            ' Days determined by column 0
            Select Case O.Value
                Case ActiveCell.FormulaR1C1 = sCurrentDays = "=NETWORKDAYS(LC[-7],TODAY(),holidays!R1C2:R10C2)"
                         
        Case "AE Review"
            ' Days determined by column P
            Select Case P.Value
                Case ActiveCell.FormulaR1C1 = sCurrentDays = "=NETWORKDAYS(LC[-8],TODAY(),holidays!R1C2:R10C2)"
                
        Case "Submitted for IRR"
            ' Days determined by column Q
            Select Case Q.Value
                Case ActiveCell.FormulaR1C1 = sCurrentDays = "=NETWORKDAYS(LC[-9],TODAY(),holidays!R1C2:R10C2)"
        
        Case "RIA Review"
            ' Days determined by column R
            Select Case R.Value
                Case ActiveCell.FormulaR1C1 = sCurrentDays = "=NETWORKDAYS(LC[-10],TODAY(),holidays!R1C2:R10C2)"
                
        Case "AE Delivery Decision"
            ' Days determined by column S
            Select Case S.Value
                Case ActiveCell.FormulaR1C1 = sCurrentDays = "=NETWORKDAYS(LC[-11],TODAY(),holidays!R1C2:R10C2)"
                
        Case "Delivery"
            ' Days determined by column T
            Select Case T.Value
                Case ActiveCell.FormulaR1C1 = sCurrentDays = "=NETWORKDAYS(LC[-12],TODAY(),holidays!R1C2:R10C2)"
                
        Case "Launch /Look Back"
            ' Days determined by column U
            Select Case U.Value
                Case ActiveCell.FormulaR1C1 = sCurrentDays = "=NETWORKDAYS(LC[-9],TODAY(),holidays!R1C2:R10C2)"
        Case Else
        ' for anything not covered above
            sCurrentDays = "Review Date"
    End Select
    CurrentDaysStatus = sCurrentDays
End Function
I could really use some help!


Second scenario:

This one is around conditional formatting. But I want the code for it in <acronym>VBA</acronym> rather than using the conditional formatting box. And if feels like it could be handled with similar code as with a case statement.

I have two cells that I would like the color the first cell based on the conditions of both cells.
Example:
If A1= "Phase 1", B1= "Incomplete" then color A1 green
else
A1= "Phase 2", B1= "Incomplete" then color A1 yellow
else
A1= "Phase 3", B1= "Incomplete" then color A1 red
else
A1= "Phase 3", B1= "Complete" then color A1 Blue

Or second Example:
If A1= "Phase 1", B1= (>=-20) then color A1 green
else
A1= "Phase 2", B1= (-6 To -19) then color A1 yellow
else
A1= "Phase 3", B1= (<=5) then color A1 red

Please help!!;)
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple

Forum statistics

Threads
1,214,943
Messages
6,122,369
Members
449,080
Latest member
Armadillos

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