Sub Worksheet_Change with named range is not does not work!

actjfc

Active Member
Joined
Jun 28, 2003
Messages
412
Excel Friends,

I set up C4:C12 to have some values that are added up at C13. I named C4:C12 as SelectedValues, and I named G3 as TotalValue and made it equal to C13. The following worksheet event does not work.

Can somebody tell me how to fix it? Just one requirement, the ranges need to be named ranges, not hard coded cells references.

Thanks!

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Debug.Print [SelectedValues].Address

Select Case Target.Address

    Case [SelectedValues].Address

    If [TotalValue] >= 100 Then

        MsgBox "T Value >= 100"

    Else

        MsgBox "T Value < 100"

    End If

End Select

End Sub
 

Some videos you may like

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.

mumps

Well-known Member
Joined
Apr 11, 2012
Messages
9,746
Try:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Intersect(Target, Range("SelectedValues")) Is Nothing Then Exit Sub
    If Range("TotalValue") >= 100 Then
        MsgBox "T Value >= 100"
    Else
        MsgBox "T Value < 100"
    End If
End Sub
 

actjfc

Active Member
Joined
Jun 28, 2003
Messages
412

ADVERTISEMENT

Now, I am having problems to make it work because I have many conditions inside of the Sub Worksheet_Change. So, I am using a Select Case statement.

When I declare it like:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)

Select Case Target.Address

Case Intersect(Target, Range("SelectedValues")) 

    If Range("TotalValue") >= 100 Then
        MsgBox "T Value >= 100"
    Else
        MsgBox "T Value < 100"
    End If

'Case ...

'Case Else

End Select

End Sub


It does not work. What am I doing wrong here? Thanks!
 

mumps

Well-known Member
Joined
Apr 11, 2012
Messages
9,746
Could you explain in detail, step by step, what you are trying to do.
 

actjfc

Active Member
Joined
Jun 28, 2003
Messages
412
Thank you! I was making it more difficult for me! I just apply your sub, and it worked. I wanted to include it as a Case in a Select Case, but it is not necessary. Thanks again!
 

Watch MrExcel Video

Forum statistics

Threads
1,114,567
Messages
5,548,822
Members
410,875
Latest member
longstrb
Top