Sub Worksheet_Change with named range is not does not work!

actjfc

Active Member
Joined
Jun 28, 2003
Messages
416
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
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
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
 
Upvote 0
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!
 
Upvote 0
Could you explain in detail, step by step, what you are trying to do.
 
Upvote 0
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!
 
Upvote 0

Forum statistics

Threads
1,223,895
Messages
6,175,257
Members
452,625
Latest member
saadat28

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