Home > Back-end >  How to use Defined Name with Taget instead of Cell address?
How to use Defined Name with Taget instead of Cell address?

Time:09-28

The below code works fine if I used cell address with target , But when I used defined Name not works , I tried Target.name and I tried If Not Intersect(Target, [Test]) Is Nothing Then but gives error

Private Sub Worksheet_Change(ByVal Target As Range)
    Application.EnableEvents = False
        If Target.Address = "$H$1" Then     '[Test] is Cell H1 in current sheet
' I tried   If Not Intersect(Target, [Test]) Is Nothing Then
            Application.EnableEvents = True
             [Quarter_Select].value = Target.value 'That ,defined Name, works without problem
               End If               
End Sub

CodePudding user response:

If the name is worksheet-scoped:

If Not Intersect(Target, Me.Names("TEST").RefersToRange) Is Nothing Then

If workbook-scoped:

If Not Intersect(Target, ThisWorkbook.Names("TEST").RefersToRange) Is Nothing Then
  • Related