Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 542
Default Split up delimited string & insert row below

Hi everyone. Im wondering how i could go about doing this. Ive setup a UDF
and one part looks like the following. A string is passed (rdText) and if it
contains a comma I need to break up the delimited text, insert however many
rows needed below where the formula is and paste the split up text there.
Thanks in advance

If InStr(1, rdText, ",") 0 Then
For Each iChar In Split(rdText, ",")
If iChar < "" Then
'insert row
'paste value to the new row
End If
Next iChar
End If
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Split up delimited string & insert row below

If you're calling the UDF from a cell on a worksheet, then you won't be able to
insert rows into your workbook.

Formulas (including your UDF) can bring back values to the cells that hold the
formulas (with minor exceptions).

But if you're using your UDF as a function that's called from a procedure,
then...

Dim mySplit As Variant
Dim HowMany As Long
Dim somecell As Range
Dim rdText As String 'my test data

rdText = "x,y,z,w"

Set somecell = ActiveSheet.Range("A1")

If InStr(1, rdText, ",", vbTextCompare) 0 Then
mySplit = Split(rdText, ",")
HowMany = UBound(mySplit) - LBound(mySplit) + 1

somecell.Offset(1, 0).Resize(HowMany).EntireRow.Insert

somecell.Offset(1, 0).Resize(HowMany).Value = Application.Transpose(mySplit)
End If

(I had no idea where it was supposed to go, so I came down 1 row from a given
cell.)



James wrote:

Hi everyone. Im wondering how i could go about doing this. Ive setup a UDF
and one part looks like the following. A string is passed (rdText) and if it
contains a comma I need to break up the delimited text, insert however many
rows needed below where the formula is and paste the split up text there.
Thanks in advance

If InStr(1, rdText, ",") 0 Then
For Each iChar In Split(rdText, ",")
If iChar < "" Then
'insert row
'paste value to the new row
End If
Next iChar
End If


--

Dave Peterson
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
Create comma-delimited string from dynamic range? Ptyrider Excel Discussion (Misc queries) 2 November 26th 07 09:04 AM
Sum delimited values in text string if... J Excel Worksheet Functions 7 February 24th 07 06:10 PM
Split non delimited data into multiple cells KJM Excel Worksheet Functions 3 September 18th 06 09:12 PM
Copy tab delimited string to worksheet row - VB6 application Ragnar Midtskogen Excel Programming 1 October 12th 05 05:35 PM
Parse a space delimited string into unique columns erighter Excel Programming 1 March 10th 05 01:01 PM


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