Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
I am trying to create multiple ranges in one column using VBA.
I have a set of data in one column and I want to create ranges for each value, eg Data: A A A B B C C C I would like a range for A, a range for B, a range for C etc Thanks Neil |
#2
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
This macro does what you want. I assumed that your data is in Column A
starting in A2. Note that your data must be sorted before you run this macro. Each range is named the value of one of the cells with "Name" after it. In other words, if the cell value is Baker, the range name assigned is BakerName. HTH Otto Sub SetRngs() Dim First As Range Dim Last As Range Dim c As Long c = 1 Set First = Range("A2") Do If First.Value < First.Offset(c).Value Then Set Last = First.Offset(c - 1) If Not IsEmpty(First.Value) Then _ Range(First, Last).Name = First.Value & "Name" Set First = Last.Offset(1) c = 1 Else c = c + 1 End If Loop Until IsEmpty(First.Value) = True End Sub wrote in message ps.com... I am trying to create multiple ranges in one column using VBA. I have a set of data in one column and I want to create ranges for each value, eg Data: A A A B B C C C I would like a range for A, a range for B, a range for C etc Thanks Neil |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Sorting Data From One Column into Multiple Columns | Excel Worksheet Functions | |||
PivotTable - Multiple Consolidation Ranges | Excel Worksheet Functions | |||
Change a Column list into multiple rows & columns | Excel Worksheet Functions | |||
Need to Improve Code Copying/Pasting Between Workbooks | Excel Discussion (Misc queries) | |||
Multiple Functions In One Column | Excel Worksheet Functions |