Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Split Cells?

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 in
choice2 the same row with
pick3 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.

Any help will be appreciated.


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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,202
Default Split Cells?

I have no idea if this is in anyway the most efficient way to do what you
asked, but the code seems to work...

Sub SplitSelectedCell()
Dim X As Long
Dim Lines() As String
Lines = Split(ActiveCell.Value, vbLf)
For X = 0 To UBound(Lines) - 1
ActiveCell.Offset(1, 0).EntireRow.Insert xlShiftDown
ActiveCell.EntireRow.Copy Destination:= _
ActiveCell.Offset(1, 1 - ActiveCell.Column)
Next
For X = 0 To UBound(Lines)
ActiveCell.Offset(X, 0).Value = Lines(X)
Next
End Sub


Rick


"jman" wrote in message
.. .
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
in
choice2
the same row with
pick3
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.

Any help will be appreciated.


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


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
Split the cells da Excel Discussion (Misc queries) 2 March 12th 10 10:26 PM
Can cells be split ? Steve Excel Worksheet Functions 5 November 23rd 09 08:28 PM
how to split cells Rockbear Excel Worksheet Functions 6 October 10th 08 09:41 PM
How to Split the contents of cells across multiple cells anna New Users to Excel 5 May 29th 08 02:47 PM
Split Cells Peeko Setting up and Configuration of Excel 2 December 17th 06 03:32 PM


All times are GMT +1. The time now is 02:11 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"