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!!;)
 

Forum statistics

Threads
1,081,543
Messages
5,359,431
Members
400,526
Latest member
Brook1083

Some videos you may like

This Week's Hot Topics

  • VBA (Userform)
    Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
  • List box that changes fill color
    Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
  • Remove duplicates and retain one. Cross-linked cases
    Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
  • VBA Copy and Paste With Duplicates
    Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
  • Macro
    is it possible for a macro to run if the active cell value is different to the value above it
  • IF DATE and TIME
    I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...
Top