Assistance in Sorting excel data

soumen21

New Member
Joined
Aug 16, 2019
Messages
35
Dear Experts,

I have some data in this format
1722868416444.png


I want to sort in the below format.

1722868462769.png


Can anyone help. I'm using Microsoft 365.

Best Regards
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Would this work for your data:

Excel Formula:
=LET(
array1,D1:D6,
array2,B1:D6,
array3,A1:B6,
non,--(NOT(ISBLANK(array1))),
a,IF(non=1,array2,""),
b,DROP(REDUCE("",SEQUENCE(3),LAMBDA(c,d,HSTACK(c,SCAN("",CHOOSECOLS(a,d),LAMBDA(a,b,IF(b<>"",b,a)))))),,1),
c,FILTER(b,non=0),
d,FILTER(array3,non=0),
CHOOSECOLS(HSTACK(c,d),1,4,5,2,3))
 
Upvote 0
@hagia_sofia's is pretty slick .. I went for something a bit more understandable (but likely slower as a result..)

Assuming your data starts in A1 - First loop is to process the data, second loop is to delete the now unwanted rows (because I couldn't find a way to do it on the first pass ;))

Just to add, it should also work where you have rows of just one, or maybe three APPROVALS as I'm pretty sure those will come up.

VBA Code:
Sub sort_data()

LR = ActiveSheet.Cells(Rows.Count, "B").End(xlUp).Row

Columns("A:A").EntireColumn.Insert

For x = 1 To LR
     
    If Range("D" & x) = "APPROVED" Then
        Range("A" & x) = Range("A" & x - 1)
        Range("D" & x) = Range("D" & x - 1)
        Range("E" & x) = Range("E" & x - 1)
    Else
        Range(Cells(x, 1), Cells(x + 1, 1)) = Range("C" & x)
              
    End If

Next x

For x = LR To 1 Step -1

    If IsNumeric(Range("B" & x)) Then Range("A" & x).EntireRow.Delete

Next x

End Sub


Book1
ABCDE
142G4000-0002TEXAS INSTRUMENTS TEXAS INSTRUMENTSLM358DR358 DUAL OP AMP, SO PKGIC-ANALOG-OPAMP
242G4000-0002TEXAS INSTRUMENTS TEXAS INSTRUMENTSLM358DRE4358 DUAL OP AMP, SO PKGIC-ANALOG-OPAMP
342G4000-0162TEXAS INSTRUMENTS TEXAS INSTRUMENTSSN74AHCT245DBR74AHCT245 OCTAL BUS XCVR SSOP-20IC-DIGITAL-LOGIC
442G4000-0162TEXAS INSTRUMENTS TEXAS INSTRUMENTSSN74AHCT245DBRG474AHCT245 OCTAL BUS XCVR SSOP-20IC-DIGITAL-LOGIC
Sheet1
 
Last edited:
Upvote 0
Solution
An alternative with Power Query aka Get and Transform Data which is on the Data Tab of the ribbon

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table2"]}[Content],
    #"Added Custom" = Table.AddColumn(Source, "Custom", each if [Column1]=100 or [Column1]=101 then [Column2] else null),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Custom.1", each if [Column1]=100 or [Column1]=101 then [Column3] else null),
    #"Filled Down" = Table.FillDown(#"Added Custom1",{"Column4", "Custom", "Custom.1"}),
    #"Filtered Rows" = Table.SelectRows(#"Filled Down", each ([Column1] = "TEXAS INSTRUMENTS TEXAS INSTRUMENTS")),
    #"Reordered Columns" = Table.ReorderColumns(#"Filtered Rows",{"Custom", "Column1", "Column2", "Column3", "Column4"})
in
    #"Reordered Columns"
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,876
Members
452,363
Latest member
merico17

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