PC Review


Reply
Thread Tools Rate Thread

Create rows from existing rows

 
 
=?Utf-8?B?Sm9lIEsu?=
Guest
Posts: n/a
 
      5th Nov 2007

I have a spreadsheet in the format listed below. I would like to
spreadsheet each number separated by semi colons into a new records.

Please help me with excel VBA code to complete this task.

Thanks,


Column A Column B Column C
Colorado 1;4;6;11;25 Denver
Florida 24;38;44;12 Miami
Illinois 13;7;8;9;10 Chicago


Desire Output
Column A Column B Column C
Colorado 1 Denver
Colorado 4 Denver
Colorado 6 Denver
Colorado 11 Denver
Colorado 25 Denver
Florida 24 Miami
Florida 38 Miami
Florida 44 Miami
Florida 12 Miami
Illinois 13 Chicago
Illinois 7 Chicago
Illinois 8 Chicago
Illinois 9 Chicago
Illinois 10 Chicago

 
Reply With Quote
 
 
 
 
Bernie Deitrick
Guest
Posts: n/a
 
      5th Nov 2007
Joe,

The macro below was written on the assumption that you have headers in row 1, and your first data
point to be split is in row 2.

If you want to retain the original sheet, copy the sheet before running the macro.

HTH,
Bernie
MS Excel MVP

Sub JoeSplit()
Dim myC As Range
Dim myV As Variant
Dim i As Integer
Dim myR As Long

For myR = Cells(Rows.Count, 2).End(xlUp).Row To 2 Step -1
myV = Split(Cells(myR, 2).Value, ";")
Cells(myR, 2).EntireRow.Copy
If UBound(myV) > 0 Then
Cells(myR, 2).Resize(UBound(myV) - LBound(myV)).EntireRow.Insert
For i = LBound(myV) To UBound(myV)
Cells(myR, 2).Offset(i, 0).Value = myV(i)
Next i
End If
Next myR

Application.CutCopyMode = False

End Sub



"Joe K." <Joe K.@discussions.microsoft.com> wrote in message
news:4E4A5628-4B0B-4CF6-9E9A-(E-Mail Removed)...
>
> I have a spreadsheet in the format listed below. I would like to
> spreadsheet each number separated by semi colons into a new records.
>
> Please help me with excel VBA code to complete this task.
>
> Thanks,
>
>
> Column A Column B Column C
> Colorado 1;4;6;11;25 Denver
> Florida 24;38;44;12 Miami
> Illinois 13;7;8;9;10 Chicago
>
>
> Desire Output
> Column A Column B Column C
> Colorado 1 Denver
> Colorado 4 Denver
> Colorado 6 Denver
> Colorado 11 Denver
> Colorado 25 Denver
> Florida 24 Miami
> Florida 38 Miami
> Florida 44 Miami
> Florida 12 Miami
> Illinois 13 Chicago
> Illinois 7 Chicago
> Illinois 8 Chicago
> Illinois 9 Chicago
> Illinois 10 Chicago
>



 
Reply With Quote
 
=?Utf-8?B?Sm9lbA==?=
Guest
Posts: n/a
 
      5th Nov 2007

try this code

Sub seperate_semicolon()

LastRow = Cells(Rows.Count, "A").End(xlUp).Row
RowCount = 1
Do While Range("A" & RowCount) <> ""
SemiColonStr = Trim(Range("B" & RowCount))
Do While Len(SemiColonStr) > 0
If InStr(SemiColonStr, ";") > 0 Then
Number = Left(SemiColonStr, InStr(SemiColonStr, ";") - 1)
SemiColonStr = Mid(SemiColonStr, InStr(SemiColonStr, ";") + 1)
Rows(RowCount + 1).Insert
Range("B" & RowCount) = Number
Range("A" & RowCount + 1) = Range("A" & RowCount)
Range("C" & RowCount + 1) = Range("C" & RowCount)
RowCount = RowCount + 1
Else
Number = SemiColonStr
Range("B" & RowCount) = Number
SemiColonStr = ""
End If
Loop

RowCount = RowCount + 1
Loop

End Sub

"Joe K." wrote:

>
> I have a spreadsheet in the format listed below. I would like to
> spreadsheet each number separated by semi colons into a new records.
>
> Please help me with excel VBA code to complete this task.
>
> Thanks,
>
>
> Column A Column B Column C
> Colorado 1;4;6;11;25 Denver
> Florida 24;38;44;12 Miami
> Illinois 13;7;8;9;10 Chicago
>
>
> Desire Output
> Column A Column B Column C
> Colorado 1 Denver
> Colorado 4 Denver
> Colorado 6 Denver
> Colorado 11 Denver
> Colorado 25 Denver
> Florida 24 Miami
> Florida 38 Miami
> Florida 44 Miami
> Florida 12 Miami
> Illinois 13 Chicago
> Illinois 7 Chicago
> Illinois 8 Chicago
> Illinois 9 Chicago
> Illinois 10 Chicago
>

 
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
Insert rows of information without overwriting existing rows? =?Utf-8?B?Sm9hbm5l?= Microsoft Word Document Management 5 14th Sep 2008 02:31 AM
How do I add many rows in between existing rows in spreadsheet? MarshaMarsha Microsoft Excel Worksheet Functions 1 27th Mar 2008 07:17 AM
Convert columns to rows: create duplicate rows based on column val =?Utf-8?B?Q2FycmllUg==?= Microsoft Access 3 30th Aug 2006 07:07 PM
Insert Rows between the existing rows =?Utf-8?B?UHJhZGVlcCBQYXRlbA==?= Microsoft Excel Misc 4 8th Oct 2005 07:43 PM
Inserting rows between existing rows using a macro Dennis Microsoft Excel Misc 0 25th Sep 2003 05:41 PM


Features
 

Advertising
 

Newsgroups
 


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