help with a macro to sort my data into readable order

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,194
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi Everyone,

So everymonth we export data that needs to be sorted out.

I need some help but its probably easiest if i show you in an example below

ABCDEFGdescription
1so in column A we have some rows that start with "P"
2P100adressaddress2addres3adress4address5address6Each one is the address for the data below it.
3order detailssoop1212341111someythingso i want a macro that can organise this data for me
4more ordersetcetcetcetcetcetcin another sheet called "Sorted"
5simply take the address that starts with P and put it into columns A to G then take each row for that order and put it into H to N so every order has the address before it
6P21if posiblle leave a space between each order?
7next lot of orders etcexample below
8
9
10P11
11next lot of orders
12
13
14Pw11
15next lot
16



ABCDEFGHIJKLMN
P100adressaddress2address3address4adress5adress6order detailssoop1212341111something
P100adressadress2adress3adrdress4adress5adress6More Ordersetcetcetcetcetcetc
P21and the same again

So sorry its a bit rushed but hopefully you can see what i mean,
Each row that starts with a "P" is the address and everything under it is the order for that address,
all i want is the info on one row for all oders?

please help if you can i'm totally stuck

Thanks

Tony
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
try this code:
VBA Code:
Sub test()
lastrow = Cells(Rows.Count, "A").End(xlUp).Row
inarr = Range(Cells(1, 1), Cells(lastrow, 7))
With Worksheets("Sorted")

.Range(.Cells(1, 1), .Cells(lastrow, 14)) = ""
outarr = .Range(.Cells(1, 1), .Cells(lastrow, 14))
Dim Adrarr(1 To 7) As Variant

indi = 2
For i = 2 To lastrow
  ft = UCase(Left(inarr(i, 1), 1))
  If ft = "P" Then
  ' copy new address
    For j = 1 To 7
     Adrarr(j) = inarr(i, j)
    Next j
  Else
  For j = 1 To 7
  outarr(indi, j) = Adrarr(j)
  outarr(indi, j + 7) = inarr(i, j)
  Next j
  indi = indi + 1
  End If
Next i
 .Range(.Cells(1, 1), .Cells(lastrow, 14)) = outarr
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,990
Messages
6,122,625
Members
449,093
Latest member
catterz66

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