PDA

View Full Version : Solved: Creating a name range in one column



wibbers2000
05-23-2009, 03:22 PM
I have a problem that I need help on.

I have attached a sheet but basically what I want to create dynamic name ranges.

column A is what I need to loop through and created a name from the cell value in column A

example; column A - A1 to A16 should be named ANTIC
column A - A17 to A27 should be named APPC
Column A - A28 to A51 should be named CaseC
etc etc

Any help is greatly received.

Regards
Paul

wibbers2000
05-23-2009, 03:58 PM
Sorry
I have checked my previous post and found that I had a solution to this previously by EL XVID (i think)

his code is below for reference



Public Sub ProcessData()
Dim i As Long
Dim LastRow As Long
Dim StartLine As Long
Dim RangeName As String

With ActiveSheet

LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
StartLine = 1
RangeName = Replace(.Cells(1, "A").Value, " ", "_")
For i = 2 To LastRow + 1

If Replace(.Cells(i, "A").Value, " ", "_") <> RangeName Then

.Cells(StartLine, "A").Offset(0, 3).Resize(i - StartLine).Name = RangeName & "_desc"
.Cells(StartLine, "A").Offset(0, 4).Resize(i - StartLine).Name = RangeName & "_code"
RangeName = Replace(.Cells(i, "A").Value, " ", "_")
StartLine = i
End If
Next i
End With
End Sub