LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 6
Default How to split cell data?

Thanks in advance for your help.
I have no VBA experience and am trying to work up a VBA macro. I have the following question:

How do I split the values in column D and place each value in a separate row along with the other data of the row as shown below?

A B C D
1 animals kitten dogs category1 (this is all
choice2 in the same
pick3 row with chr(10) seperator.)

Below is the desired result:

A B C D
1 animals kitten dogs category1
2 animals kitten dogs choice2
3 animals kitten dogs pick3


I found the following code which will output the Column D values in separate rows but it does not bring along the other row data (Columns A, B, C) as I need. How
can I modify this code to include the other row data for each "split off" value of Col D? Or, is there some other way to do it altogether?

Partial solution below? \ \ \ \ \ \ \ \

If Cell D divided by the Chr(10) character, then this will place the items

Public Sub Split()
n = 1
strt = 1
For i = 1 To Len(Selection)
If Mid(Selection, i, 1) = Chr(10) Then
Selection.Offset(n, 0) = Mid(Selection, strt, i - strt)
strt = i + 1
n = n + 1
End If
Next i
Selection.Offset(n, 0) = Mid(Selection, strt, i - strt)
End Sub

To run the above, select the cell you want to split and run the Macro (Alt F8, select Split/Run). The individual values are output below. It will overwrite anything
already there.
Thanks for your help.


--
--------------------------------- --- -- -
Posted with NewsLeecher v3.7 Final
Web @ http://www.newsleecher.com/?usenet
------------------- ----- ---- -- -

 
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
Split data in a cell Slashman Excel Worksheet Functions 4 August 28th 06 01:31 AM
Split cell data in mutiple rows [email protected] Excel Discussion (Misc queries) 2 July 18th 06 07:55 AM
How to seperate data in a cell which is split by a comma Eamonn Excel Worksheet Functions 1 March 29th 06 09:30 AM
how to split data into columns and arrange the resulting data jack Excel Discussion (Misc queries) 1 November 11th 05 11:20 PM
Split data from one cell to two separate cells Michele Excel Worksheet Functions 2 October 25th 05 09:27 PM


All times are GMT +1. The time now is 12:09 AM.

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"