Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Spreadsheet cleanup help

Hi I have not done much excel programming but have a task I need some
help with. I have a worksheet with information that I need to copy
and maniplulate onto another spreadsheet. the data in worksheet one
looks as follows:

Row Col1 Col2 Col3
A B 1
1 2
3

Basically in the source worksheet you have 3 columns and in col3 you
have some text that has new line characters. i need to copy this row
to my new worksheet and split col3 at each new line charcter so that
it looks this in the new worksheet:

Row Col1 Col2 Col3
1 A B 1
2 2
3 3

Any quick way to do this with VBA would be very helpful
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Spreadsheet cleanup help

Give this macro a try (changing the Source and Destination assignments as
needed)...

Sub SplitCellLines()
Dim Source As Range, Destination As Range, Lines As Variant

Set Source = Worksheets("Sheet4").Range("C1")
Set Destination = Worksheets("Sheet5").Range("C1")

Lines = Split(Source, vbLf)
Destination.Resize(UBound(Lines) + 1) = _
WorksheetFunction.Transpose(Split(Source, vbLf))
End Sub

--
Rick (MVP - Excel)


"Mike Miller" wrote in message
...
Hi I have not done much excel programming but have a task I need some
help with. I have a worksheet with information that I need to copy
and maniplulate onto another spreadsheet. the data in worksheet one
looks as follows:

Row Col1 Col2 Col3
A B 1
1 2
3

Basically in the source worksheet you have 3 columns and in col3 you
have some text that has new line characters. i need to copy this row
to my new worksheet and split col3 at each new line charcter so that
it looks this in the new worksheet:

Row Col1 Col2 Col3
1 A B 1
2 2
3 3

Any quick way to do this with VBA would be very helpful


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Spreadsheet cleanup help

On Oct 28, 12:33*pm, "Rick Rothstein"
wrote:
Give this macro a try (changing the Source and Destination assignments as
needed)...

Sub SplitCellLines()
* Dim Source As Range, Destination As Range, Lines As Variant

* Set Source = Worksheets("Sheet4").Range("C1")
* Set Destination = Worksheets("Sheet5").Range("C1")

* Lines = Split(Source, vbLf)
* Destination.Resize(UBound(Lines) + 1) = _
* * * * * * * * * * *WorksheetFunction.Transpose(Split(Source, vbLf))
End Sub

--
Rick (MVP - Excel)

"Mike Miller" wrote in message

...



Hi I have not done much excel programming but have a task I need some
help with. *I have a worksheet with information that I need to copy
and maniplulate onto another spreadsheet. *the data in worksheet one
looks as follows:


Row * Col1 * Col2 * *Col3
* * * * *A * * * *B * * * *1
1 * * * * * * * * * * * * * * 2
* * * * * * * * * * * * * * * 3


Basically in the source worksheet you have 3 columns and in col3 you
have some text that has new line characters. *i need to copy this row
to my new worksheet and split col3 at each new line charcter so that
it looks this in the new worksheet:


Row * Col1 * Col2 * *Col3
1 * * * *A * * * *B * * * *1
2 * * * * * * * * * * * * * * 2
3 * * * * * * * * * * * * * * 3


Any quick way to do this with VBA would be very helpful


Next question on this would be how to loop the above through a
spreadsheet with 5000 rows.

M
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Spreadsheet cleanup help

For future questions that you may ask on these newsgroups, please do not
simplify your question for us... just ask the actual question you are
looking to get a solution for... that way, the volunteers here won't end up
wasting their time creating solutions for situations you don't actually care
about.

For the question you have now asked, give the following macro a try. To make
things easier for you to change in case the starting cell of C1 and the
destination cell of C1 were just simplifications of your actual layout, I
have included a set of Const (constant) statements where you can set the
relevant layout conditions.

Sub SplitCellLines()
Dim Cell As Range, Source As Range, Destination As Range
Dim X As Long, LastRow As Long, NextRow As Long, Lines As Variant

Const SourceStartRow As Long = 1
Const SourceColumn As String = "C"
Const SourceSheetName As String = "Sheet4"
Const DestinationStartRow As Long = 1
Const DestinationColumn As String = "C"
Const DestinationSheetName As String = "Sheet5"

Set Destination = Worksheets(DestinationSheetName). _
Cells(DestinationStartRow, DestinationColumn)
With Worksheets(SourceSheetName)
LastRow = .Cells(.Rows.Count, SourceColumn).End(xlUp).Row
For X = SourceStartRow To LastRow
Set Source = .Cells(X, SourceColumn)
Lines = Split(Source.Value, vbLf)
Destination.Offset(NextRow).Resize(UBound(Lines) + 1) = _
WorksheetFunction.Transpose(Split(Source.Value, vbLf))
NextRow = NextRow + UBound(Lines) + 1
Next
End With
End Sub

--
Rick (MVP - Excel)


"Mike Miller" wrote in message
...
On Oct 28, 12:33 pm, "Rick Rothstein"
wrote:
Give this macro a try (changing the Source and Destination assignments as
needed)...

Sub SplitCellLines()
Dim Source As Range, Destination As Range, Lines As Variant

Set Source = Worksheets("Sheet4").Range("C1")
Set Destination = Worksheets("Sheet5").Range("C1")

Lines = Split(Source, vbLf)
Destination.Resize(UBound(Lines) + 1) = _
WorksheetFunction.Transpose(Split(Source, vbLf))
End Sub

--
Rick (MVP - Excel)

"Mike Miller" wrote in message

...



Hi I have not done much excel programming but have a task I need some
help with. I have a worksheet with information that I need to copy
and maniplulate onto another spreadsheet. the data in worksheet one
looks as follows:


Row Col1 Col2 Col3
A B 1
1 2
3


Basically in the source worksheet you have 3 columns and in col3 you
have some text that has new line characters. i need to copy this row
to my new worksheet and split col3 at each new line charcter so that
it looks this in the new worksheet:


Row Col1 Col2 Col3
1 A B 1
2 2
3 3


Any quick way to do this with VBA would be very helpful


Next question on this would be how to loop the above through a
spreadsheet with 5000 rows.

M

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
Data cleanup sjs Excel Worksheet Functions 1 September 16th 09 03:37 PM
Code Cleanup P J H Excel Programming 3 February 3rd 06 03:27 PM
Code cleanup peter.thompson[_53_] Excel Programming 2 January 18th 06 06:16 AM
Code cleanup help please peter.thompson[_8_] Excel Programming 5 December 22nd 05 07:08 AM
Log File CleanUp [email protected][_2_] Excel Programming 1 December 7th 04 06:19 PM


All times are GMT +1. The time now is 07:55 AM.

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

About Us

"It's about Microsoft Excel"