Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default Splitting Cell content into separate Rows

I have a Spreadsheet that looks like the following,

Name Order Date Order
John Smith 06/05/14 A,B,C,D
Mike Doe 06/02/26 B,C,E

and so on... with several thousand entries.

I need the database to be structured in the following way.

Name Order Date Order
John Smith 06/05/14 A
John Smith 06/05/14 B
John Smith 06/05/14 C
John Smith 06/05/14 D
Mike Doe 06/02/26 B
Mike Doe 06/02/26 C
Mike Doe 06/02/26 E

Is there any way that I can make this happen using a macro or applet of
some sort? Does anyone have one that will do this already?
Things to note are that all orders are currently separated by a comma
followed by a single space, these must be removed.

If anyone can help, thanks in advance.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Splitting Cell content into separate Rows


It isn't pretty, but it works.

Sub SplitSeparate()
Application.ScreenUpdating = False
Dim r As Integer, r2 As Integer
Dim c As Integer, c2 As Integer
r = 0
r2 = 0
c = 3
c2 = 0
Columns("C:C").Select
Selection.TextToColumns Destination:=Range("C1")
DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=True
Tab:=True, _
Semicolon:=False, Comma:=True, Space:=True, Other:=False
FieldInfo:= _
Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4, 1))
TrailingMinusNumbers:= _
True

Range("A2").Select
Do
Do
If IsEmpty(ActiveCell.Offset(r, c)) = False Then
r2 = r2 + 1
ActiveCell.Offset(r2, 0).EntireRow.Insert
Range(ActiveCell.Offset(r, 0), ActiveCell.Offset(r, c)).Copy
Range(ActiveCell.Offset(r2, 0).Address).PasteSpecial
Range(ActiveCell.Offset(0, c).Address).Copy
Range(ActiveCell.Offset(0, 2).Address).PasteSpecial
Application.CutCopyMode = False
c = c + 1
Else
c = c + 1
r2 = r2 + 1
End If
ActiveCell.Offset(-r2, -2).Activate
Loop Until IsEmpty(ActiveCell.Offset(r, c)) = True
r = r2
ActiveCell.Offset(r + 1, 0).Activate
r = 0
r2 = 0
If c c2 Then c2 = c
c = 3
Loop Until IsEmpty(ActiveCell) = True
Range("D1", ActiveCell.Offset(0, c2
1).Address).EntireColumn.ClearContents
Application.ScreenUpdating = True
End Sub

JokerFrowns Wrote:
I have a Spreadsheet that looks like the following,
.
.
.
Is there any way that I can make this happen using a macro or apple
of
some sort? Does anyone have one that will do this already?
Things to note are that all orders are currently separated by a comma
followed by a single space, these must be removed.

If anyone can help, thanks in advance


--
Ikaabo
-----------------------------------------------------------------------
Ikaabod's Profile: http://www.excelforum.com/member.php...fo&userid=3337
View this thread: http://www.excelforum.com/showthread.php?threadid=54252

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default Splitting Cell content into separate Rows

Many thanks,

I am no excel buff, do I just insert this into the code console and
away I go?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Splitting Cell content into separate Rows


In excel you can hit alt-F11, then click INSERT-MODULE and paste the
code in there. You can run the code a number of ways (i.e. - create a
command button that runs the macro, or manually run it in Microsoft VB
Editor, etc.) Let me know if you have problems.
JokerFrowns Wrote:
Many thanks,

I am no excel buff, do I just insert this into the code console and
away I go?



--
Ikaabod
------------------------------------------------------------------------
Ikaabod's Profile: http://www.excelforum.com/member.php...o&userid=33371
View this thread: http://www.excelforum.com/showthread...hreadid=542520

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Splitting Cell content into separate Rows


There is one thing that needs changed actually. Change:
ActiveCell.Offset(-r2, -2).Activate
to
If ActiveCell.Column < 1 Then ActiveCell.Offset(-r2, -2).Activate


--
Ikaabod
------------------------------------------------------------------------
Ikaabod's Profile: http://www.excelforum.com/member.php...o&userid=33371
View this thread: http://www.excelforum.com/showthread...hreadid=542520



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default Splitting Cell content into separate Rows

I am getting an error compiling syntax in the following line:

Selection.TextToColumns Destination:=Range("C1"),

Am I doing something wrong or forgetting something?

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
splitting cell content from 1st column into 4 columns Daphtg Excel Worksheet Functions 1 April 28th 10 10:30 PM
Splitting a cell into rows instead of columns Tix Excel Discussion (Misc queries) 12 April 16th 09 08:41 PM
Splitting out Content in 1 cell (which is currently separated by"ALT-ENTER") into multiple cells Sunil Ahuja Excel Discussion (Misc queries) 1 March 24th 09 04:27 PM
Splitting a concatenated string into separate rows... Natarajan Excel Worksheet Functions 1 May 4th 06 05:57 PM
IF function - need to evaluate cell content in 2 separate files-#N PBM Excel Worksheet Functions 3 July 5th 05 08:17 AM


All times are GMT +1. The time now is 11:57 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"