Leonvl
New Member
- Joined
- Apr 26, 2016
- Messages
- 20
When a cell in the range A1:A100 is changed (added), I want to define a named range that referring to the two cells to the right. The name of the range can be the value of the target cell. I tried the below code but it doesnt work for some reason...
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim NamedRange As Range
Dim RangeName As String
If Not Intersect(Target, Range("A1:A100")) Is Nothing Then
Set NamedRange = Worksheets("Blad1").Range(Target.Offset(, 1), Target.Offset(, 2))
RangeName = Target.Value
Target.Names.Add Name:=RangeName, RefersTo:=NamedRange
End If
End Sub