LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5,651
Default Parsing, separating, inserting. copying

On Tue, 16 Jun 2009 02:35:32 -0700 (PDT), Philipgrae
wrote:

Just seen what a mess the data looks like when posted.....

To explain, there should be four columns in the example, A to D. In
each is a piece of data (Date, Name, Delimited text and Text.

There are four rows, 1 to 4.

In the output, ther are still four columns, with the delimited text
separated out into new rows, thus increasing the number of rows in the
set to 6.

I need the non-delimited data that remains in the set to be copied UP
into the blank cells created by the separation and placement of the
delimited data.

I hope that makes sense!

P ;)


Perhaps not so elegant as Tom's, but it should work to do what you describe.

It was not clear to me from your descriptions if your original data had only
four columns, or if there could be more. I wrote the routine so it would
handle n columns.

Important assumptions:
Delimited text is in column 1
Data Source is a NAME'd range (named on the worksheet).
Destination starts in A1, and a A1.CurrentRegion.ClearContents will not
destroy anything valuable. But you may want to look at this method of clearing
out old data critically before applying it.

=============================
Option Explicit
Sub ReformatData()
Dim rSrc As Range, c As Range, rDest As Range
Dim i As Long, j As Long, k As Long
Dim sTemp() As String
Const sSep As String = ";#"

Set rSrc = Range("OrigDataTbl")
Set rDest = Range("A1")

rDest.CurrentRegion.ClearContents

i = 0
For j = 1 To rSrc.Rows.Count
Set rDest = rDest(1 + i, 1)
Set c = rSrc(j, 1)
sTemp = Split(c.Value, sSep)
For i = 0 To UBound(sTemp)
rDest(i + 1, 1).Value = sTemp(i)
For k = 2 To rSrc.Columns.Count
With rDest(i + 1, k)
.Value = c(1, k)
.NumberFormat = c(1, k).NumberFormat
End With
Next k
Next i
Next j
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
copying formulas when inserting new rows Steve M[_4_] Excel Discussion (Misc queries) 7 September 8th 08 02:55 PM
Inserting multiple rows and copying formulas [email protected] Excel Discussion (Misc queries) 3 September 13th 07 03:24 PM
Macro: copying, inserting & autofilling. Steve Simons Excel Discussion (Misc queries) 2 September 19th 06 03:50 PM
Copying row & inserting Chance224 Excel Discussion (Misc queries) 1 September 2nd 06 03:03 AM
Automatically copying fomulae when Inserting rows Ian Goodhardt Excel Discussion (Misc queries) 3 August 17th 05 07:01 PM


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