Rearrange data in spreadsheet to specific format

NKUNZI

New Member
Joined
Feb 8, 2019
Messages
13
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Please assist with an automated way either formula or VBA, to remove and place order No to left of ICN no for each order under that order No, and have a sequential list without spaces.
this requires that the items under each order no needs to be identified in turn and matched to the items in the order. An example of what the sheet looks like is given below, this needs to be changed to place the EGU-ORD No next to only the lines with a cat no, ignoring lines that have other data, then sort all the items so that they appear sequentially under the order no, removing data that does not have the order no next to the cat no so should look something like this:
order no ICN Product QTY
EGU-ORD/21-11-1547 6016020 Pethidine 50mg/mL Ampoule [INJ] 400
EGU-ORD/21-11-1551 6200805 Acetazolamide 250mg Tablet [PO] 72
EGU-ORD/21-11-1551 6203655 Allopurinol 300mg Tablet [PO] 200 removing lines containing Total line items, Total lines received, OrderNo once aligned left etc
ICNProduct
EGU-ORD/21-11-1547
6016020Pethidine 50mg/mL Ampoule [INJ]
Total Line Items:
Total Lines Fully Received:
EGU-ORD/21-11-1551
6200805Acetazolamide 250mg Tablet [PO]
6203655Allopurinol 300mg Tablet [PO]
6803615Aluminium Hydroxide 300mg/5mL Gel [PO]
6051013Amitriptyline 25mg Tablet [PO]
6147016Ibuprofen 400mg Tablet [PO]
6147084Ibuprofen 400mg Tablet [PO]
6441816Insulin, Soluble And Isophane 30/70%, Brown 100IU/mL Syringe, Prefilled [SC]
6441788Insulin, Soluble, Fast Acting, Yellow 100IU/mL Syringe, Prefilled [SC]
ICNProduct
EGU-ORD/21-11-1551
6441532Insulin, Soluble, Fast Acting, Yellow 100IU/mL Vial [SC]
6844230Lactulose 3.35g/5mL Syrup [PO]
6862830Liquid Paraffin BP Liquid [PO]
6248310Loperamide 2mg Tablet [PO]
6156056Metformin 500mg Tablet [PO]
Total Line Items:
Total Lines Fully Received:
EGU-ORD/22-01-1595
6404430Amoxycillin, Clavulanic Acid 1000&200mg Vial [INJ]
Total Line Items:
Total Lines Fully Received:
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Assuming the data starts in cell A1, the QTY is in column C, like this:
Dante Amor
ABC
1
2CNProduct
3EGU-ORD/21-11-1547
46016020Pethidine 50mg/mL Ampoule [INJ]400
5Total Line Items:
6Total Lines Fully Received:
7EGU-ORD/21-11-1551
86200805Acetazolamide 250mg Tablet [PO]72
96203655Allopurinol 300mg Tablet [PO]200
Hoja4


The result in cell E2 onwards, like this:
Dante Amor
EFGH
1
2EGU-ORD/21-11-15476016020Pethidine 50mg/mL Ampoule [INJ]400
3EGU-ORD/21-11-15516200805Acetazolamide 250mg Tablet [PO]72
4EGU-ORD/21-11-15516203655Allopurinol 300mg Tablet [PO]20
Hoja4


Try this:
VBA Code:
Sub Rearrange()
  Dim c As Range, num As String
  For Each c In Range("A1", Range("A" & Rows.Count).End(3))
    If Left(c.Value, 3) = "EGU" Then num = c.Value
    If Left(c.Value, 1) Like "*[0-9]*" Then Range("E" & Rows.Count).End(3)(2).Resize(1, 4).Value = Array(num, c, c.Offset(, 1), c.Offset(, 2))
  Next
End Sub
 
Upvote 0
Solution
Much appreciated,
Not exactly what I needed but is in the right ballpark, so gives me something to work with. Apologies I failed to say and clarify that this data should be placed in a new workbook. Where what I need in essence are rows containing the order no, icn no, product, qty and price.
The thinking was that if I can see how the icn & products are aligned then I can expand along similar lines for qty and price.
So based on the data that I gave you, you cracked it 100% and for this I am truly grateful, it allows me to work with it and then assign to a new workbook and worksheet.
Would appreciate if I can call on your help if I get stuck in that area.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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