Try this amended code
Option Explicit
Sub addName()
Dim rng As Range
Dim cl As Range
Dim MyRange As Range
Dim MyRange2 As Range
Dim MyRange3 As Range
Set rng = Range(Cells(2, 4), Cells(Rows.Count, 4).End(xlUp))
For Each cl In rng
Select Case cl.Value
Case 7
If MyRange Is Nothing Then
Set MyRange = Range(Cells(cl.Row, 1), Cells(cl.Row, 15))
Else: Set MyRange = Union(MyRange, Range(Cells(cl.Row, 1), Cells(cl.Row, 15)))
End If
Case 2
If MyRange2 Is Nothing Then
Set MyRange2 = Range(Cells(cl.Row, 1), Cells(cl.Row, 15))
Else: Set MyRange2 = Union(MyRange2, Range(Cells(cl.Row, 1), Cells(cl.Row, 15)))
End If
Case 8
If MyRange3 Is Nothing Then
Set MyRange3 = Range(Cells(cl.Row, 1), Cells(cl.Row, 15))
Else: Set MyRange3 = Union(MyRange3, Range(Cells(cl.Row, 1), Cells(cl.Row, 15)))
End If
End Select
Next cl
With ThisWorkbook
.Names.Add Name:="newnt", _
RefersTo:=MyRange, Visible:=True
.Names.Add Name:="oldt", _
RefersTo:=MyRange2, Visible:=True
.Names.Add Name:="newt", _
RefersTo:=MyRange3, Visible:=True
End With
End Sub
Bookmarks