Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Splitting text in cell with Excel 97 VBA macro

Hi!

Can somebody help me in the next problem:

I need to transform (split) a sample text in a cell into N-row table
(or array) where N is equal to number of words in the text. Separators
may be "," or ", ". How can I do that with VBA in Excel 97 (only!)?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Splitting text in cell with Excel 97 VBA macro

Hi Vsevolod,

For your purposes (xl97), try a function from Tom Ogilvy:

Function Split97(sStr As Variant, sdelim As String) _
As Variant
Split97 = Evaluate("{""" & _
Application.Substitute(sStr, sdelim, """,""") _
& """}")
End Function

---
Regards,
Norman


"Vsevolod" wrote in message
m...
Hi!

Can somebody help me in the next problem:

I need to transform (split) a sample text in a cell into N-row table
(or array) where N is equal to number of words in the text. Separators
may be "," or ", ". How can I do that with VBA in Excel 97 (only!)?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Splitting text in cell with Excel 97 VBA macro

Interestingly I have been unable to get a macro to work on a comm
delimited cell without a "Type mismatch" error.

I suggest you record a macro using Data/Text to columns on the cell an
then add code to go through the cells to Trim() the value.

Come back with any probs

--
Message posted from http://www.ExcelForum.com

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Splitting text in cell with Excel 97 VBA macro

Hi Brian,

The following works for me:

Sub test()

Dim myArr As Variant
Dim mystr As String
Dim i As Long

mystr = "the, old, brown, fox"

myArr = Split97(Trim(mystr), ",")

For i = LBound(myArr) To UBound(myArr)
Debug.Print myArr(i)
Next
'Or:

Sheets(3).Range("A1").Resize(UBound(myArr), 1) _
= Application.Transpose(myArr)

End Sub

---
Regards,
Norman

"BrianB " wrote in message
...
Interestingly I have been unable to get a macro to work on a comma
delimited cell without a "Type mismatch" error.

I suggest you record a macro using Data/Text to columns on the cell and
then add code to go through the cells to Trim() the value.

Come back with any probs.


---
Message posted from http://www.ExcelForum.com/



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
E2007 - Macro for splitting text and then replacing something Niniel Excel Discussion (Misc queries) 2 November 18th 09 10:11 AM
splitting cell text using macro Garrystone Excel Discussion (Misc queries) 3 February 1st 08 03:22 PM
Splitting text in a cell Richard_123 Excel Worksheet Functions 4 July 27th 07 08:24 PM
splitting text from one cell rogera Excel Discussion (Misc queries) 1 January 10th 06 01:43 PM
splitting text in a cell.. via135 Excel Discussion (Misc queries) 5 December 23rd 05 01:04 AM


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