VBA Conditional IF With Multiple Variable Ranges

Hello EE,
MacroShadow assisted me with the code below and it works great with one variable (KeyCell1), but I as I am attempting to incorporate the second variable KeyCell2 and it is not working.  Any Ideas?


Private Sub Worksheet_Change(ByVal Target As Range)

    Dim KeyCells As Range
    ' The variables KeyCell1 and KeyCell2 contains the cells that will
    ' update the record count for retained students according to the term specified.
    Set KeyCell1 = Range("K2")
    Set KeyCell2 = Range("J2")

    If Not Application.Intersect(KeyCell1, Range(Target.Address), KeyCell2, Range(Target.Address)) Is Nothing Then
        If KeyCell1 = 10 And KeyCell2 = 10 Then
            Range("H23").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[cohort_cde].&[""&R2C7&""]"",""[Table_TMSEPRD].[NR - FALL GROUP].&[""&RC1&""]"")"
            Range("H32").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[COHORT YEAR GROUP].&[""&$C$9&""]"",""[Table_TMSEPRD].[COHORT TERM GROUP].&[""&$J$2&""]"",""[Table_TMSEPRD].[NR - FALL GROUP].&[""&$A23&""]"")"
            Range("H47").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[cohort_cde].&[""&R2C7&""]"",""[Table_TMSEPRD].[NR - FALL GROUP].&[""&RC1&""]"")"
            Range("H50").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[COHORT YEAR GROUP].&[""&$C$9&""]"",""[Table_TMSEPRD].[COHORT TERM GROUP].&[""&$J$2&""]"",""[Table_TMSEPRD].[NR - FALL GROUP].&[""&$A23&""]"")"
            Range("H59").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[cohort_cde].&[""&R2C7&""]"",""[Table_TMSEPRD].[NR - FALL GROUP].&[""&RC1&""]"")"
            Range("H68").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[COHORT YEAR GROUP].&[""&$C$9&""]"",""[Table_TMSEPRD].[COHORT TERM GROUP].&[""&$J$2&""]"",""[Table_TMSEPRD].[NR - FALL GROUP].&[""&$A23&""]"")"
            Range("H77").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[cohort_cde].&[""&R2C7&""]"",""[Table_TMSEPRD].[NR - FALL GROUP].&[""&RC1&""]"")"
            Range("H86").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[COHORT YEAR GROUP].&[""&$C$9&""]"",""[Table_TMSEPRD].[COHORT TERM GROUP].&[""&$J$2&""]"",""[Table_TMSEPRD].[NR - FALL GROUP].&[""&$A23&""]"")"
            Range("H95").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[cohort_cde].&[""&R2C7&""]"",""[Table_TMSEPRD].[NR - FALL GROUP].&[""&RC1&""]"")"
            Range("H104").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[COHORT YEAR GROUP].&[""&$C$9&""]"",""[Table_TMSEPRD].[COHORT TERM GROUP].&[""&$J$2&""]"",""[Table_TMSEPRD].[NR - FALL GROUP].&[""&$A23&""]"")"
            Range("H113").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[cohort_cde].&[""&R2C7&""]"",""[Table_TMSEPRD].[NR - FALL GROUP].&[""&RC1&""]"")"
            Range("H122").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[COHORT YEAR GROUP].&[""&$C$9&""]"",""[Table_TMSEPRD].[COHORT TERM GROUP].&[""&$J$2&""]"",""[Table_TMSEPRD].[NR - FALL GROUP].&[""&$A23&""]"")"
        
        ElseIf KeyCell1 = 20 And KeyCell2 = 20 Then
            Range("H23").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[cohort_cde].&[""&R2C7&""]"",""[Table_TMSEPRD].[NR - SPRING GROUP].&[""&RC1&""]"")"
            Range("H32").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[COHORT YEAR GROUP].&[""&$C$9&""]"",""[Table_TMSEPRD].[COHORT TERM GROUP].&[""&$J$2&""]"",""[Table_TMSEPRD].[NR - SPRING GROUP].&[""&$A23&""]"")"
            Range("H47").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[cohort_cde].&[""&R2C7&""]"",""[Table_TMSEPRD].[NR - SPRING GROUP].&[""&RC1&""]"")"
            Range("H50").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[COHORT YEAR GROUP].&[""&$C$9&""]"",""[Table_TMSEPRD].[COHORT TERM GROUP].&[""&$J$2&""]"",""[Table_TMSEPRD].[NR - SPRING GROUP].&[""&$A23&""]"")"
            Range("H59").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[cohort_cde].&[""&R2C7&""]"",""[Table_TMSEPRD].[NR - SPRING GROUP].&[""&RC1&""]"")"
            Range("H68").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[COHORT YEAR GROUP].&[""&$C$9&""]"",""[Table_TMSEPRD].[COHORT TERM GROUP].&[""&$J$2&""]"",""[Table_TMSEPRD].[NR - SPRING GROUP].&[""&$A23&""]"")"
            Range("H77").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[cohort_cde].&[""&R2C7&""]"",""[Table_TMSEPRD].[NR - SPRING GROUP].&[""&RC1&""]"")"
            Range("H86").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[COHORT YEAR GROUP].&[""&$C$9&""]"",""[Table_TMSEPRD].[COHORT TERM GROUP].&[""&$J$2&""]"",""[Table_TMSEPRD].[NR - SPRING GROUP].&[""&$A23&""]"")"
            Range("H95").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[cohort_cde].&[""&R2C7&""]"",""[Table_TMSEPRD].[NR - SPRING GROUP].&[""&RC1&""]"")"
            Range("H104").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[COHORT YEAR GROUP].&[""&$C$9&""]"",""[Table_TMSEPRD].[COHORT TERM GROUP].&[""&$J$2&""]"",""[Table_TMSEPRD].[NR - SPRING GROUP].&[""&$A23&""]"")"
            Range("H113").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[cohort_cde].&[""&R2C7&""]"",""[Table_TMSEPRD].[NR - SPRING GROUP].&[""&RC1&""]"")"
            Range("H122").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[COHORT YEAR GROUP].&[""&$C$9&""]"",""[Table_TMSEPRD].[COHORT TERM GROUP].&[""&$J$2&""]"",""[Table_TMSEPRD].[NR - SPRING GROUP].&[""&$A23&""]"")"
        
        ElseIf KeyCell1 = 10 And KeyCell2 = 20 Then
            Range("H23").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[cohort_cde].&[""&R2C7&""]"",""[Table_TMSEPRD].[NR - FALL GROUP].&[""&RC1&""]"")"
            Range("H32").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[COHORT YEAR GROUP].&[""&$C$9&""]"",""[Table_TMSEPRD].[COHORT TERM GROUP].&[""&$J$2&""]"",""[Table_TMSEPRD].[NR - FALL GROUP].&[""&$A23&""]"")"
            Range("H47").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[cohort_cde].&[""&R2C7&""]"",""[Table_TMSEPRD].[NR - SPRING GROUP].&[""&RC1&""]"")"
            Range("H50").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[COHORT YEAR GROUP].&[""&$C$9&""]"",""[Table_TMSEPRD].[COHORT TERM GROUP].&[""&$J$2&""]"",""[Table_TMSEPRD].[NR - SPRING GROUP].&[""&$A23&""]"")"
            Range("H59").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[cohort_cde].&[""&R2C7&""]"",""[Table_TMSEPRD].[NR - FALL GROUP].&[""&RC1&""]"")"
            Range("H68").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[COHORT YEAR GROUP].&[""&$C$9&""]"",""[Table_TMSEPRD].[COHORT TERM GROUP].&[""&$J$2&""]"",""[Table_TMSEPRD].[NR - FALL GROUP].&[""&$A23&""]"")"
            Range("H77").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[cohort_cde].&[""&R2C7&""]"",""[Table_TMSEPRD].[NR - SPRING GROUP].&[""&RC1&""]"")"
            Range("H86").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[COHORT YEAR GROUP].&[""&$C$9&""]"",""[Table_TMSEPRD].[COHORT TERM GROUP].&[""&$J$2&""]"",""[Table_TMSEPRD].[NR - SPRING GROUP].&[""&$A23&""]"")"
            Range("H95").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[cohort_cde].&[""&R2C7&""]"",""[Table_TMSEPRD].[NR - FALL GROUP].&[""&RC1&""]"")"
            Range("H104").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[COHORT YEAR GROUP].&[""&$C$9&""]"",""[Table_TMSEPRD].[COHORT TERM GROUP].&[""&$J$2&""]"",""[Table_TMSEPRD].[NR - FALL GROUP].&[""&$A23&""]"")"
            Range("H113").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[cohort_cde].&[""&R2C7&""]"",""[Table_TMSEPRD].[NR - FALL GROUP].&[""&RC1&""]"")"
            Range("H122").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[COHORT YEAR GROUP].&[""&$C$9&""]"",""[Table_TMSEPRD].[COHORT TERM GROUP].&[""&$J$2&""]"",""[Table_TMSEPRD].[NR - FALL GROUP].&[""&$A23&""]"")"
        
        ElseIf KeyCell1 = 20 And KeyCell2 = 10 Then
            Range("H23").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[cohort_cde].&[""&R2C7&""]"",""[Table_TMSEPRD].[NR - SPRING GROUP].&[""&RC1&""]"")"
            Range("H32").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[COHORT YEAR GROUP].&[""&$C$9&""]"",""[Table_TMSEPRD].[COHORT TERM GROUP].&[""&$J$2&""]"",""[Table_TMSEPRD].[NR - SPRING GROUP].&[""&$A23&""]"")"
            Range("H47").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[cohort_cde].&[""&R2C7&""]"",""[Table_TMSEPRD].[NR - FALL GROUP].&[""&RC1&""]"")"
            Range("H50").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[COHORT YEAR GROUP].&[""&$C$9&""]"",""[Table_TMSEPRD].[COHORT TERM GROUP].&[""&$J$2&""]"",""[Table_TMSEPRD].[NR - FALL GROUP].&[""&$A23&""]"")"
            Range("H59").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[cohort_cde].&[""&R2C7&""]"",""[Table_TMSEPRD].[NR - SPRING GROUP].&[""&RC1&""]"")"
            Range("H68").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[COHORT YEAR GROUP].&[""&$C$9&""]"",""[Table_TMSEPRD].[COHORT TERM GROUP].&[""&$J$2&""]"",""[Table_TMSEPRD].[NR - SPRING GROUP].&[""&$A23&""]"")"
            Range("H77").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[cohort_cde].&[""&R2C7&""]"",""[Table_TMSEPRD].[NR - FALL GROUP].&[""&RC1&""]"")"
            Range("H86").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[COHORT YEAR GROUP].&[""&$C$9&""]"",""[Table_TMSEPRD].[COHORT TERM GROUP].&[""&$J$2&""]"",""[Table_TMSEPRD].[NR - FALL GROUP].&[""&$A23&""]"")"
            Range("H95").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[cohort_cde].&[""&R2C7&""]"",""[Table_TMSEPRD].[NR - SPRING GROUP].&[""&RC1&""]"")"
            Range("H104").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[COHORT YEAR GROUP].&[""&$C$9&""]"",""[Table_TMSEPRD].[COHORT TERM GROUP].&[""&$J$2&""]"",""[Table_TMSEPRD].[NR - SPRING GROUP].&[""&$A23&""]"")"
            Range("H113").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[cohort_cde].&[""&R2C7&""]"",""[Table_TMSEPRD].[NR - FALL GROUP].&[""&RC1&""]"")"
            Range("H122").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[COHORT YEAR GROUP].&[""&$C$9&""]"",""[Table_TMSEPRD].[COHORT TERM GROUP].&[""&$J$2&""]"",""[Table_TMSEPRD].[NR - FALL GROUP].&[""&$A23&""]"")"
        
        Else
                End If
            End If
        End Sub

Open in new window

Lindsay_KAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Martin LissOlder than dirtCommented:
Dim rngUnion As Range

Set rngUnion = Union(Range("K2"), Range("J2"))

If Not Application.Intersect(rngUnion, Range(Target.Address)) Is Nothing Then

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Lindsay_KAuthor Commented:
Thank you Marin :)

I've incorporated your solution, but is not updating the formulas and I am getting a type mismatch compile error that I believe is due to my If statements not using the rngUnion correctly?  I did some research through Google, but was not able to find an reference that defined how to use this in the IF statement in the way that I am trying to use it.

Private Sub Worksheet_Change(ByVal Target As Range)

    Dim rngUnion As Range
    ' The variables KeyCell1 and KeyCell2 contains the cells that will
    ' update the record count for retained students according to the term specified.
    Set rngUnion = Union(Range("J2"), Range("K2"))

    If Not Application.Intersect(rngUnion, Range(Target.Address)) Is Nothing Then
        If rngUnion = Union(10, 10) Then
            Range("H23").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[cohort_cde].&[""&R2C7&""]"",""[Table_TMSEPRD].[NR - FALL GROUP].&[""&RC1&""]"")"
            Range("H32").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[COHORT YEAR GROUP].&[""&$C$9&""]"",""[Table_TMSEPRD].[COHORT TERM GROUP].&[""&$J$2&""]"",""[Table_TMSEPRD].[NR - FALL GROUP].&[""&$A23&""]"")"
            Range("H41").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[cohort_cde].&[""&R2C7&""]"",""[Table_TMSEPRD].[NR - FALL GROUP].&[""&RC1&""]"")"
            Range("H50").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[COHORT YEAR GROUP].&[""&$C$9&""]"",""[Table_TMSEPRD].[COHORT TERM GROUP].&[""&$J$2&""]"",""[Table_TMSEPRD].[NR - FALL GROUP].&[""&$A23&""]"")"
            Range("H59").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[cohort_cde].&[""&R2C7&""]"",""[Table_TMSEPRD].[NR - FALL GROUP].&[""&RC1&""]"")"
            Range("H68").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[COHORT YEAR GROUP].&[""&$C$9&""]"",""[Table_TMSEPRD].[COHORT TERM GROUP].&[""&$J$2&""]"",""[Table_TMSEPRD].[NR - FALL GROUP].&[""&$A23&""]"")"
            Range("H77").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[cohort_cde].&[""&R2C7&""]"",""[Table_TMSEPRD].[NR - FALL GROUP].&[""&RC1&""]"")"
            Range("H86").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[COHORT YEAR GROUP].&[""&$C$9&""]"",""[Table_TMSEPRD].[COHORT TERM GROUP].&[""&$J$2&""]"",""[Table_TMSEPRD].[NR - FALL GROUP].&[""&$A23&""]"")"
            Range("H95").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[cohort_cde].&[""&R2C7&""]"",""[Table_TMSEPRD].[NR - FALL GROUP].&[""&RC1&""]"")"
            Range("H104").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[COHORT YEAR GROUP].&[""&$C$9&""]"",""[Table_TMSEPRD].[COHORT TERM GROUP].&[""&$J$2&""]"",""[Table_TMSEPRD].[NR - FALL GROUP].&[""&$A23&""]"")"
            Range("H113").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[cohort_cde].&[""&R2C7&""]"",""[Table_TMSEPRD].[NR - FALL GROUP].&[""&RC1&""]"")"
            Range("H122").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[COHORT YEAR GROUP].&[""&$C$9&""]"",""[Table_TMSEPRD].[COHORT TERM GROUP].&[""&$J$2&""]"",""[Table_TMSEPRD].[NR - FALL GROUP].&[""&$A23&""]"")"
        
        ElseIf rngUnion = Union(20, 20) Then
            Range("H23").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[cohort_cde].&[""&R2C7&""]"",""[Table_TMSEPRD].[NR - SPRING GROUP].&[""&RC1&""]"")"
            Range("H32").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[COHORT YEAR GROUP].&[""&$C$9&""]"",""[Table_TMSEPRD].[COHORT TERM GROUP].&[""&$J$2&""]"",""[Table_TMSEPRD].[NR - SPRING GROUP].&[""&$A23&""]"")"
            Range("H41").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[cohort_cde].&[""&R2C7&""]"",""[Table_TMSEPRD].[NR - SPRING GROUP].&[""&RC1&""]"")"
            Range("H50").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[COHORT YEAR GROUP].&[""&$C$9&""]"",""[Table_TMSEPRD].[COHORT TERM GROUP].&[""&$J$2&""]"",""[Table_TMSEPRD].[NR - SPRING GROUP].&[""&$A23&""]"")"
            Range("H59").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[cohort_cde].&[""&R2C7&""]"",""[Table_TMSEPRD].[NR - SPRING GROUP].&[""&RC1&""]"")"
            Range("H68").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[COHORT YEAR GROUP].&[""&$C$9&""]"",""[Table_TMSEPRD].[COHORT TERM GROUP].&[""&$J$2&""]"",""[Table_TMSEPRD].[NR - SPRING GROUP].&[""&$A23&""]"")"
            Range("H77").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[cohort_cde].&[""&R2C7&""]"",""[Table_TMSEPRD].[NR - SPRING GROUP].&[""&RC1&""]"")"
            Range("H86").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[COHORT YEAR GROUP].&[""&$C$9&""]"",""[Table_TMSEPRD].[COHORT TERM GROUP].&[""&$J$2&""]"",""[Table_TMSEPRD].[NR - SPRING GROUP].&[""&$A23&""]"")"
            Range("H95").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[cohort_cde].&[""&R2C7&""]"",""[Table_TMSEPRD].[NR - SPRING GROUP].&[""&RC1&""]"")"
            Range("H104").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[COHORT YEAR GROUP].&[""&$C$9&""]"",""[Table_TMSEPRD].[COHORT TERM GROUP].&[""&$J$2&""]"",""[Table_TMSEPRD].[NR - SPRING GROUP].&[""&$A23&""]"")"
            Range("H113").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[cohort_cde].&[""&R2C7&""]"",""[Table_TMSEPRD].[NR - SPRING GROUP].&[""&RC1&""]"")"
            Range("H122").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[COHORT YEAR GROUP].&[""&$C$9&""]"",""[Table_TMSEPRD].[COHORT TERM GROUP].&[""&$J$2&""]"",""[Table_TMSEPRD].[NR - SPRING GROUP].&[""&$A23&""]"")"
        
        ElseIf rngUnion = Union(10, 20) Then
            Range("H23").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[cohort_cde].&[""&R2C7&""]"",""[Table_TMSEPRD].[NR - FALL GROUP].&[""&RC1&""]"")"
            Range("H32").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[COHORT YEAR GROUP].&[""&$C$9&""]"",""[Table_TMSEPRD].[COHORT TERM GROUP].&[""&$J$2&""]"",""[Table_TMSEPRD].[NR - FALL GROUP].&[""&$A23&""]"")"
            Range("H41").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[cohort_cde].&[""&R2C7&""]"",""[Table_TMSEPRD].[NR - SPRING GROUP].&[""&RC1&""]"")"
            Range("H50").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[COHORT YEAR GROUP].&[""&$C$9&""]"",""[Table_TMSEPRD].[COHORT TERM GROUP].&[""&$J$2&""]"",""[Table_TMSEPRD].[NR - SPRING GROUP].&[""&$A23&""]"")"
            Range("H59").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[cohort_cde].&[""&R2C7&""]"",""[Table_TMSEPRD].[NR - FALL GROUP].&[""&RC1&""]"")"
            Range("H68").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[COHORT YEAR GROUP].&[""&$C$9&""]"",""[Table_TMSEPRD].[COHORT TERM GROUP].&[""&$J$2&""]"",""[Table_TMSEPRD].[NR - FALL GROUP].&[""&$A23&""]"")"
            Range("H77").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[cohort_cde].&[""&R2C7&""]"",""[Table_TMSEPRD].[NR - SPRING GROUP].&[""&RC1&""]"")"
            Range("H86").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[COHORT YEAR GROUP].&[""&$C$9&""]"",""[Table_TMSEPRD].[COHORT TERM GROUP].&[""&$J$2&""]"",""[Table_TMSEPRD].[NR - SPRING GROUP].&[""&$A23&""]"")"
            Range("H95").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[cohort_cde].&[""&R2C7&""]"",""[Table_TMSEPRD].[NR - FALL GROUP].&[""&RC1&""]"")"
            Range("H104").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[COHORT YEAR GROUP].&[""&$C$9&""]"",""[Table_TMSEPRD].[COHORT TERM GROUP].&[""&$J$2&""]"",""[Table_TMSEPRD].[NR - FALL GROUP].&[""&$A23&""]"")"
            Range("H113").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[cohort_cde].&[""&R2C7&""]"",""[Table_TMSEPRD].[NR - FALL GROUP].&[""&RC1&""]"")"
            Range("H122").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[COHORT YEAR GROUP].&[""&$C$9&""]"",""[Table_TMSEPRD].[COHORT TERM GROUP].&[""&$J$2&""]"",""[Table_TMSEPRD].[NR - FALL GROUP].&[""&$A23&""]"")"
        
        ElseIf rngUnion = Union(20, 10) Then
            Range("H23").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[cohort_cde].&[""&R2C7&""]"",""[Table_TMSEPRD].[NR - SPRING GROUP].&[""&RC1&""]"")"
            Range("H32").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[COHORT YEAR GROUP].&[""&$C$9&""]"",""[Table_TMSEPRD].[COHORT TERM GROUP].&[""&$J$2&""]"",""[Table_TMSEPRD].[NR - SPRING GROUP].&[""&$A23&""]"")"
            Range("H41").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[cohort_cde].&[""&R2C7&""]"",""[Table_TMSEPRD].[NR - FALL GROUP].&[""&RC1&""]"")"
            Range("H50").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[COHORT YEAR GROUP].&[""&$C$9&""]"",""[Table_TMSEPRD].[COHORT TERM GROUP].&[""&$J$2&""]"",""[Table_TMSEPRD].[NR - FALL GROUP].&[""&$A23&""]"")"
            Range("H59").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[cohort_cde].&[""&R2C7&""]"",""[Table_TMSEPRD].[NR - SPRING GROUP].&[""&RC1&""]"")"
            Range("H68").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[COHORT YEAR GROUP].&[""&$C$9&""]"",""[Table_TMSEPRD].[COHORT TERM GROUP].&[""&$J$2&""]"",""[Table_TMSEPRD].[NR - SPRING GROUP].&[""&$A23&""]"")"
            Range("H77").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[cohort_cde].&[""&R2C7&""]"",""[Table_TMSEPRD].[NR - FALL GROUP].&[""&RC1&""]"")"
            Range("H86").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[COHORT YEAR GROUP].&[""&$C$9&""]"",""[Table_TMSEPRD].[COHORT TERM GROUP].&[""&$J$2&""]"",""[Table_TMSEPRD].[NR - FALL GROUP].&[""&$A23&""]"")"
            Range("H95").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[cohort_cde].&[""&R2C7&""]"",""[Table_TMSEPRD].[NR - SPRING GROUP].&[""&RC1&""]"")"
            Range("H104").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[COHORT YEAR GROUP].&[""&$C$9&""]"",""[Table_TMSEPRD].[COHORT TERM GROUP].&[""&$J$2&""]"",""[Table_TMSEPRD].[NR - SPRING GROUP].&[""&$A23&""]"")"
            Range("H113").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[cohort_cde].&[""&R2C7&""]"",""[Table_TMSEPRD].[NR - FALL GROUP].&[""&RC1&""]"")"
            Range("H122").Formula = "=CUBEVALUE(""PowerPivot Data"",""[Measures].[Distinct Count of ID_NUM]"",""[Table_TMSEPRD].[COHORT YEAR GROUP].&[""&$C$9&""]"",""[Table_TMSEPRD].[COHORT TERM GROUP].&[""&$J$2&""]"",""[Table_TMSEPRD].[NR - FALL GROUP].&[""&$A23&""]"")"
        
        Else
                End If
            End If
        End Sub

Open in new window

Martin LissOlder than dirtCommented:
Using rngUnion in the If Not Application.Intersect(rngUnion, Range(Target.Address)) Is Nothing Then line will tell you if either of the two cells have been changed. After that I believe you should just used your KeyCell1and 2 ranges, so for example line 9 in you last post should be If KeyCell1 = 10 And KeyCell2 = 10 Then like it was before.
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Lindsay_KAuthor Commented:
Got it worked out with your guidance, despite my cell reference errors!  Thank you so much Martin :)
FarWestCommented:
also if you have separated cells to be monitored you can do this
Private Sub Worksheet_Change(ByVal Target As Range)
If InStr(1, "|$K$2|$J$2|", "|" & LTrim(RTrim(Target.Address)) & "|", 0) > 0 Then 'you can put as many cells separated by vertical bar
MsgBox ("my range changed")
End If
End Sub

Open in new window

Lindsay_KAuthor Commented:
Awesome FarWest!  Thank you...I've added this to my syntax library :)
Martin LissOlder than dirtCommented:
You're welcome and I'm glad I was able to help.

In my profile you'll find links to some articles I've written that may interest you.
Marty - MVP 2009 to 2014
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.