PC Review


Reply
Thread Tools Rate Thread

Convert Range of Years to Individual list (integers)

 
 
brian@justsuspension.com
Guest
Posts: n/a
 
      6th May 2009
For example, I need to convert this:

1995-2000 (1 column, 1 row)

to this:

1995
1996
1997
1998
1999
2000 (1 column, 6 rows)

If anyone can help, it will be greatly appreciated!

 
Reply With Quote
 
 
 
 
Per Jessen
Guest
Posts: n/a
 
      6th May 2009
Hi

Look at this:

Sub aaa()
Dim Del As Long
Dim StartYear As Long
Dim EndYear As Long
Dim y As Long
Dim off As Long

Del = WorksheetFunction.Find("-", Range("A1").Value)
StartYear = Left(Range("A1").Value, Del - 1)
EndYear = Mid(Range("A1").Value, Del + 1)
For y = StartYear To EndYear
Range("A1").Offset(off, 0) = y
off = off + 1
Next
End Sub


Regards,
Per

On 6 Maj, 23:19, br...@justsuspension.com wrote:
> For example, I need to convert this:
>
> 1995-2000 (1 column, 1 row)
>
> to this:
>
> 1995
> 1996
> 1997
> 1998
> 1999
> 2000 (1 column, 6 rows)
>
> If anyone can help, it will be greatly appreciated!


 
Reply With Quote
 
RB Smissaert
Guest
Posts: n/a
 
      6th May 2009
You could do something like this:

Sub SplitYears()

Dim i As Long
Dim r As Long
Dim arrYears

arrYears = Split(Cells(1), "-")

For i = arrYears(0) To arrYears(UBound(arrYears))
r = r + 1
Cells(r, 1) = i
Next i

End Sub


RBS


<(E-Mail Removed)> wrote in message
news:1e8048ae-6257-42cf-85a6-(E-Mail Removed)...
> For example, I need to convert this:
>
> 1995-2000 (1 column, 1 row)
>
> to this:
>
> 1995
> 1996
> 1997
> 1998
> 1999
> 2000 (1 column, 6 rows)
>
> If anyone can help, it will be greatly appreciated!
>


 
Reply With Quote
 
brian@justsuspension.com
Guest
Posts: n/a
 
      6th May 2009
Thanks for the quick responses, everyone! Let me make my project a
little more clear and see what you think. The year values are part of
a group of data, and the other data needs to be copied intact along
with the expanded year values. For example, convert this:

(3 columns, 2 rows)
Acura EL 2002-2005
Acura Integra 1990-1993

To this:

(3 columns, 7 rows)
Acura EL 2002
Acura EL 2003
Acura EL 2004
Acura EL 2005
Acura Integra 1990
Acura Integra 1991
Acura Integra 1992

 
Reply With Quote
 
Per Jessen
Guest
Posts: n/a
 
      6th May 2009
Hi

You never told where you want output to be placed, so I placed it in
Sheet2, assuming input data is in Sheet1.

Sub aaa()
Dim Del As Long
Dim StartYear As Long
Dim EndYear As Long
Dim y As Long
Dim off As Long
Dim OutputSh As Worksheet

Set OutputSh = Worksheets("Sheet2")
FirstRow = 2 ' Headings in Row 1
LastRow = Range("A" & Rows.Count).End(xlUp).Row
For r = FirstRow To LastRow
Del = WorksheetFunction.Find("-", Range("C" & r).Value)
StartYear = Left(Range("C" & r).Value, Del - 1)
EndYear = Mid(Range("C" & r).Value, Del + 1)
For y = StartYear To EndYear
OutputSh.Range("C2").Offset(off, 0) = y
OutputSh.Range("A2").Offset(off, 0) = Range("A" & r).Value
OutputSh.Range("B2").Offset(off, 0) = Range("B" & r).Value
off = off + 1
Next
Next
End Sub

Regards,
Per

On 7 Maj, 00:13, br...@justsuspension.com wrote:
> Thanks for the quick responses, everyone! *Let me make my project a
> little more clear and see what you think. *The year values are part of
> a group of data, and the other data needs to be copied intact along
> with the expanded year values. *For example, convert this:
>
> (3 columns, 2 rows)
> Acura EL 2002-2005
> Acura Integra 1990-1993
>
> To this:
>
> (3 columns, 7 rows)
> Acura EL 2002
> Acura EL 2003
> Acura EL 2004
> Acura EL 2005
> Acura Integra 1990
> Acura Integra 1991
> Acura Integra 1992


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
convert range of years to series autoguy Microsoft Excel Programming 10 19th Oct 2009 06:02 PM
convert a range of cells into individual worksheets? KL in OK Microsoft Excel Misc 1 23rd Jan 2008 01:11 AM
Re: Convert Data Range in to individual values Don Guillett Microsoft Excel Misc 0 7th Jun 2006 04:48 PM
Re: Convert Data Range in to individual values robert111 Microsoft Excel Misc 0 7th Jun 2006 02:33 PM
A list of Consecutive Integers, can I search for missing integers =?Utf-8?B?Q00=?= Microsoft Excel Worksheet Functions 4 2nd Sep 2005 06:38 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:16 AM.