Need VBA to arrange data in cells using delimiters? I'm stumped.

andyfox1979

New Member
Joined
Dec 5, 2012
Messages
32
So I have some data exported from an ecommerce store. Tabe delimited file. I've created two delimiters, ^ and ##:

^ is before each order number. This indicates notes are over, or new order number

## indicates notes begin. If there is nothing after this across the row (say, 5 rows over) then notes are empty, output should just be order number and blank notes.

Want to join all associated notes after the ## and 5 rows across and before the next ^ in a cell below--- join all of this in a single corresponding cell on an seperate output page.

Example Data


OrderNotesNotes2
^485 ## 2004 Jun 26 18:51: Marked Cancelled
> 2004 Jun 26 18:51: Cancelled; Reason: Customer changed mind
> 2004 Jul 6 10:41: Modified by Wayland
^486## CancelledByTom
^487##

<tbody>
</tbody>

Desired Output

OrderNotesNotes2
4852004 Jun 26 18:51: Marked Cancelled by Wayland > 2004 Jun 26 18:51: Cancelled; Reason: Customer changed mind > 2004 Jul 6 10:41: Modified by Wayland
486Cancelled By Tom
487

<tbody>
</tbody>


Any hints on where to go from here would be greatly appreciated!
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Each order in its own row with the # adjacent is a much better data structure, do you agree?

Yes, I wish it exported like that, but it exported exactly like this. I removed some consistent junk data and replaced it with delimiters in order to be able to figure it out programatically but i'm stuck.

If you look at the example Data and Output its exactly what i'm trying to achieve here :)
 
Upvote 0
This is how I'd refine it:


Excel 2010
AB
1GroupOrder
2485^485 ## 2004 Jun 26 18:51: Marked Cancelled
3485> 2004 Jun 26 18:51: Cancelled; Reason: Customer changed mind
4485> 2004 Jul 6 10:41: Modified by Wayland
5486^486## Cancelled
6487^487##
Sheet11
Cell Formulas
RangeFormula
A2=IF(LEFT(B2,1)="^",MID(B2,2,3),A1)


You can probably follow the order # pattern without adding delimiters
 
Upvote 0
You can probably follow the order # pattern without adding delimiters[/QUOTE said:
Thanks for taking a crack at it. Extracting the order numbers isn't my challenge, my issue is that i want to keep the notes tied to each order number, so the logical solution is to set some delimiters so that after ## it checks the immediate cell, and then the adjacent cell in the next 5 columns, adding any notes to a single output cell on the 2nd page... it would then return to the next row below and continues adding that to the notes until it reaches another ^, which would then indicate an order number and do the above over again.


^549 ##
^550 ##
^551 ## 2004 Oct 4 15:40: Marked Pending Review by Wayland
> 2004 Oct 4 15:40: Marked Pending Review:
> 2004 Oct 6 07:24: Marked OK by Wayland
> 2004 Oct 6 07:24: Marked OK:
^552 ##
^553 ##
^554 ##
^555 ##

<colgroup><col></colgroup><tbody>
</tbody>
 
Upvote 0
^549 ##
^550 ##
^551 ## 2004 Oct 4 15:40: Marked Pending Review by Wayland
> 2004 Oct 4 15:40: Marked Pending Review:
> 2004 Oct 6 07:24: Marked OK by Wayland
> 2004 Oct 6 07:24: Marked OK:
^552 ##
^553 ##
^554 ##
^555 ##

<colgroup><col></colgroup><tbody>
</tbody>



Exactly like this, except there's some useless formatting around the order number (store id, etc). There's nothing unique that encapsulates the notes unfortunately. The only thing I could identify is where the notes begin and when they end (new order numer or ^).
 
Upvote 0
If you don't mind code you can try this.

It assumes your data starts in A1 and there are no blank cells in column A.

It will check the first six columns in each row for data.

Code:
Sub andygox1979()
Dim rngData As Range
Dim x, strTemp As String, j, nr As Long, k, r As Long, c As Long
With ActiveSheet.Range("A1").CurrentRegion
    Set rngData = .Offset(1).Resize(.Rows.Count - 1, 6)
End With
x = rngData
Application.ScreenUpdating = False
rngData.ClearContents
    For r = LBound(x, 1) To UBound(x, 1)
        For c = LBound(x, 2) To UBound(x, 2)
            strTemp = strTemp & IIf(x(r, c) = vbEmpty, "", x(r, c) & " ")
        Next c
    Next r

x = Split(strTemp, "^")
nr = 2
    For Each j In x
        If j <> "" Then
        k = Split(j, "##")
        Cells(nr, 1).Value = Trim(k(0))
        Cells(nr, 2).Value = Trim(k(1))
        nr = nr + 1
        End If
    Next j
Columns("A:B").AutoFit
Application.ScreenUpdating = True
End Sub
 
Last edited:
Upvote 0
Here's a before and after running the code.

Sheet1

*ABCDE
1OrderNotesNotes2**
2^485 ## 2004 Jun 26 18:51: Marked Cancelled****
3> 2004 Jun 26 18:51: Cancelled; Reason: Customer changed mind****
4> 2004 Jul 6 10:41: Modified by Wayland****
5^486## CancelledByTom and*Joe
6^487##****

<colgroup><col style="font-weight:bold; width:30px; "><col style="width:422.67px;"><col style="width:149.33px;"><col style="width:62.67px;"><col style="width:64px;"><col style="width:64px;"></colgroup>





Excel Workbook
AB
1OrderNotes
24852004 Jun 26 18:51: Marked Cancelled > 2004 Jun 26 18:51: Cancelled; Reason: Customer changed mind > 2004 Jul 6 10:41: Modified by Wayland
3486Cancelled By Tom and Joe
4487*
Sheet1
 
Last edited:
Upvote 0
Bruce this is awesome, thanks so much... what do do if there are blank cells in column A? (unfortunately there are)
 
Upvote 0

Forum statistics

Threads
1,215,219
Messages
6,123,680
Members
449,116
Latest member
HypnoFant

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top