Thanks it really gave me the way to start. Here is the end code ant the attachment.
Again, many thanks and probably, see you around!
Sub SetNames()
Dim BegRw As Long, EndRw As Long, RngName As String, SheetName As String, LastRow As Long, Range As String
Const NameCol = 19 ' Adjust as needed
Const DescCol = "D"
Call Pre_SetNames 'Macro to add * that show the end of the range
With ActiveSheet 'finds last used row
LastRow = .Cells(.Rows.Count, "S").End(xlUp).Row
End With
BegRw = 4
RngName = Cells(BegRw, NameCol).Value
SheetName = ActiveSheet.Name
If RngName = "" Then
MsgBox "First name not found"
Exit Sub
End If
Do Until EndRw >= LastRow
If RngName = "*" Then '"*" is a reference, the next field is the range name (RngName)
RngName = Cells(BegRw, NameCol).Value
End If
Do Until RngName = "*" Or EndRw >= LastRow
EndRw = BegRw + 1
Do Until Cells(EndRw, NameCol).Value <> "" Or Cells(EndRw, 1).Value = "*"
EndRw = EndRw + 1
Loop
ActiveWorkbook.Names.Add Name:=RngName, _
RefersTo:="='" & SheetName & "'!$" & DescCol & "$" & BegRw & ":$" & DescCol & "$" & EndRw
BegRw = EndRw + 1
RngName = Cells(BegRw - 1, NameCol).Value
Loop
Loop
End Sub
'Macro to prepare the table
Sub Pre_SetNames()
Dim Rw As Long, LastRow1 As Long
Const NameCol2 = 19
Const NameCol1 = 1
With ActiveSheet
LastRow1 = .Cells(.Rows.Count, "S").End(xlUp).Row
End With
Rw = 3
Do Until Rw >= LastRow1
Rw = Rw + 1
If Cells(Rw, NameCol1) <> "" And Cells(Rw - 1, NameCol1) = "" Then
Cells(Rw - 1, NameCol2) = "*"
End If
Loop
Cells(LastRow1 + 1, NameCol1) = "*"
Cells(LastRow1 + 1, NameCol2) = ""
End Sub
09.01.png
Bookmarks