LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 5,651
Default Splitting the characters in the cell



To split to columns, with some maximum number of columns, you can try this
macro:

==========================================
Sub SplitToColumns()
Const MaxCols As Long = 256 'set this to whatever or use inputbox
Const Comma As String = ","
Dim c As Range
Dim i As Long
Dim sSplitArray() As String

For Each c In Selection
sSplitArray = Split(c.Value, Comma)

For i = 0 To UBound(sSplitArray)
c(1 + Int(i / MaxCols), 2 + i Mod MaxCols).Value =
Replace(Trim(sSplitArray(i)), vbLf, "")
Next i
Next c
End Sub
=============================================
--ron


I noticed my newsreader wrapped a line in this second macro in the wrong spot.
So as to prevent that, I forced a line break appropriately:

=============================================
Sub SplitToColumns()
Const MaxCols As Long = 3 'set this to whatever or use inputbox
Const Comma As String = ","
Dim c As Range
Dim i As Long
Dim sSplitArray() As String

For Each c In Selection
sSplitArray = Split(c.Value, Comma)

For i = 0 To UBound(sSplitArray)
c(1 + Int(i / MaxCols), 2 + i Mod MaxCols).Value = _
Replace(Trim(sSplitArray(i)), vbLf, "")
Next i
Next c
End Sub
===========================================
--ron


 
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 a Cell williamr Excel Worksheet Functions 2 June 13th 07 01:30 AM
splitting cell anand Excel Worksheet Functions 2 June 1st 07 11:13 PM
Splitting a cell by number of characters from the end David P. Excel Discussion (Misc queries) 4 April 10th 07 03:46 PM
Splitting a cell c Excel Worksheet Functions 1 April 12th 05 02:40 PM
Splitting a Cell c Excel Worksheet Functions 5 April 11th 05 10:23 PM


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