Data sorting

Moharam

New Member
Joined
Jan 5, 2022
Messages
8
Office Version
  1. 2016
  2. 2007
Platform
  1. Windows
Hi Guys please help me with this, I need to sort this as per below criteria.

Data.xlsx
ABC
1Actual Data
2Order IDProductsQty
32018000499421D Capsules,C Cider Vinegar,AB Oil2,1,1
42018000486403D Capsules,C Cider Vinegar,AB Oil2,1,1
52018000499744S Xtreme Power - 1,C Cider Vinegar,D Capsules,AB Oil1,1,2,1
6
7
8Required Data
9Order IDProductsQty
102018000499421D Capsules2
112018000499421C Cider Vinegar1
122018000499421AB Oil1
132018000486403D Capsules2
142018000486403C Cider Vinegar1
152018000486403AB Oil1
162018000499744S Xtreme Power - 11
172018000499744C Cider Vinegar1
182018000499744D Capsules2
192018000499744AB Oil1
Sheet1
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Please try:

I assumed the first row starts in A2. Header in A1


VBA Code:
Sub jec()
 Dim ar, jv, sp As Variant, i As Long, j As Long, x As Long
 ar = Cells(1).CurrentRegion
 ReDim jv(2, 0)
 
 For i = 2 To UBound(ar)
    sp = Split(ar(i, 2), ",")
    For j = 0 To UBound(sp)
       ReDim Preserve jv(2, x)
        jv(0, x) = ar(i, 1)
        jv(1, x) = sp(j)
        jv(2, x) = Split(ar(i, 3), ",")(j)
        x = x + 1
     Next
 Next
 
 Cells(1, 7).Resize(x, 3) = Application.Transpose(jv)
End Sub
 
Upvote 0
You can also include the header by just changing this

For i = 2 To UBound(ar)

to

For i = 1 To UBound(ar)
 
Upvote 0
Thank you So Much Guys, Its helped me a lot....!! I am grateful to you.
 
Upvote 0
Please try:

I assumed the first row starts in A2. Header in A1


VBA Code:
Sub jec()
 Dim ar, jv, sp As Variant, i As Long, j As Long, x As Long
 ar = Cells(1).CurrentRegion
 ReDim jv(2, 0)
 
 For i = 2 To UBound(ar)
    sp = Split(ar(i, 2), ",")
    For j = 0 To UBound(sp)
       ReDim Preserve jv(2, x)
        jv(0, x) = ar(i, 1)
        jv(1, x) = sp(j)
        jv(2, x) = Split(ar(i, 3), ",")(j)
        x = x + 1
     Next
 Next
 
 Cells(1, 7).Resize(x, 3) = Application.Transpose(jv)
End Sub

Please try:

I assumed the first row starts in A2. Header in A1


VBA Code:
Sub jec()
 Dim ar, jv, sp As Variant, i As Long, j As Long, x As Long
 ar = Cells(1).CurrentRegion
 ReDim jv(2, 0)
 
 For i = 2 To UBound(ar)
    sp = Split(ar(i, 2), ",")
    For j = 0 To UBound(sp)
       ReDim Preserve jv(2, x)
        jv(0, x) = ar(i, 1)
        jv(1, x) = sp(j)
        jv(2, x) = Split(ar(i, 3), ",")(j)
        x = x + 1
     Next
 Next
 
 Cells(1, 7).Resize(x, 3) = Application.Transpose(jv)
End Sub
Hi JEC,

Thank you for your code, but the said code is not working properly. Its not considering the QTY also not considering the lines. Please look into and help me.

Thanks
 

Attachments

  • Error.JPG
    Error.JPG
    74.9 KB · Views: 7
Upvote 0
Can you post some sample data again?
 
Upvote 0
Can you post some sample data again?
Original Data
Order IDProduct NameQty
225219Skygain Bulls King Lube Oil,Skygain Bulls King-10 Caps1,1
225186Shilajit Resin Pack of 1,Skygain Bulls King-10 Caps1,1
225155Skygain BullsKing Men's Supplement Capsule,Skygain Bulls King Lube Oil1,1
225152Skygain Bulls King Lube Oil,Skygain BullsKing Men's Supplement Capsule1,1
225107Skygain Bulls King Lube Oil,Skygain BullsKing Men's Supplement Capsule1,2
225106Skygain BullsKing Men's Supplement Capsule,Skygain Bulls King Lube Oil1,1
225102Nutriherbs Shilajit 60 Capsules (500 Mg),Skygain Bulls King Lube Oil1,1
225096Nutriherbs Ohyes Shilajit , Safed Musli & Ashwagandha - 60 Capsule (Pack Of 1),16 Again - Himalayan Raw Ayurvedic Shilajit - 15g (Natural Source of Fulvic Acid and Trace Minerals),Red Wine Vinegar 473ml,Xtreme Power Booster-15Caps1,1,1,1



Required Data
Order IDProduct NameQty
225219Skygain Bulls King Lube Oil1
225219Skygain Bulls King-10 Caps1
225186Shilajit Resin Pack of 11
225186Skygain Bulls King-10 Caps1
225155Skygain BullsKing Men's Supplement Capsule1
225155Skygain Bulls King Lube Oil1
225152Skygain Bulls King Lube Oil1
225152Skygain BullsKing Men's Supplement Capsule1
225107Skygain Bulls King Lube Oil1
225107Skygain BullsKing Men's Supplement Capsule2
225106Skygain BullsKing Men's Supplement Capsule1
225106Skygain Bulls King Lube Oil1
225102Nutriherbs Shilajit 60 Capsules (500 Mg)1
225102Skygain Bulls King Lube Oil1
225096Nutriherbs Ohyes Shilajit , Safed Musli & Ashwagandha - 60 Capsule (Pack Of 1)1
22509616 Again - Himalayan Raw Ayurvedic Shilajit - 15g (Natural Source of Fulvic Acid and Trace Minerals)1
225096Red Wine Vinegar 473ml1
225096Xtreme Power Booster-15Caps1
 
Upvote 0
In the last row you miss a "1"
Should be:

1,1,1,1,1
 
Upvote 0

Forum statistics

Threads
1,215,219
Messages
6,123,687
Members
449,117
Latest member
Aaagu

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