Formula to extract unique values as a horizontal list

willow1985

Well-known Member
Joined
Jul 24, 2019
Messages
888
Office Version
  1. 365
Platform
  1. Windows
Hello,

I have tried a few formulas (index match with count if) But I cannot seem to get the results I am looking for.

I have a list of areas that I would like unique values transposed horizontally (see below picture)

Any help would be appreciated ( I think I am missing something in my formula attempts)

Thank you!

1601499001508.png
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
How about
+Fluff New.xlsm
ABCDEFGHIJKLMN
1CountyDerbyshireWest YorkshireStaffordshireGreater ManchesterSomersetCumbriaShropshireCounty DurhamLancashireNorthumberlandSouth Yorkshire 
2Derbyshire
3West Yorkshire
4Derbyshire
5Derbyshire
6West Yorkshire
7Derbyshire
8Staffordshire
9Derbyshire
10West Yorkshire
11Greater Manchester
12West Yorkshire
13West Yorkshire
14West Yorkshire
15West Yorkshire
16Staffordshire
17Somerset
18Cumbria
19Shropshire
20West Yorkshire
21County Durham
22Staffordshire
23West Yorkshire
24Lancashire
25Northumberland
26Lancashire
27South Yorkshire
28Greater Manchester
29Derbyshire
30West Yorkshire
31County Durham
32West Yorkshire
33Lancashire
34West Yorkshire
Main
Cell Formulas
RangeFormula
C1:N1C1=IFERROR(INDEX($A$2:$A$34,AGGREGATE(15,6,(ROW($A$2:$A$34)-ROW($A$2)+1)/(ISNA(MATCH($A$2:$A$34,$B1:B1,0))),1)),"")
 
Upvote 0
How about
+Fluff New.xlsm
ABCDEFGHIJKLMN
1CountyDerbyshireWest YorkshireStaffordshireGreater ManchesterSomersetCumbriaShropshireCounty DurhamLancashireNorthumberlandSouth Yorkshire 
2Derbyshire
3West Yorkshire
4Derbyshire
5Derbyshire
6West Yorkshire
7Derbyshire
8Staffordshire
9Derbyshire
10West Yorkshire
11Greater Manchester
12West Yorkshire
13West Yorkshire
14West Yorkshire
15West Yorkshire
16Staffordshire
17Somerset
18Cumbria
19Shropshire
20West Yorkshire
21County Durham
22Staffordshire
23West Yorkshire
24Lancashire
25Northumberland
26Lancashire
27South Yorkshire
28Greater Manchester
29Derbyshire
30West Yorkshire
31County Durham
32West Yorkshire
33Lancashire
34West Yorkshire
Main
Cell Formulas
RangeFormula
C1:N1C1=IFERROR(INDEX($A$2:$A$34,AGGREGATE(15,6,(ROW($A$2:$A$34)-ROW($A$2)+1)/(ISNA(MATCH($A$2:$A$34,$B1:B1,0))),1)),"")

I see the position of this formula matters quite a bit. What if I wanted the horizontal list on another sheet, say sheet 2, starting at A1,

How would that work?

Also is there a way to get rid of the "0" result when it hits the end? rather just have blanks...

Thank you so much!
 
Upvote 0
You could not have it in A1 as there has to be at least one cell to the left of the formula.
 
Upvote 0
Hi
is it like this by changing index ranges
Feedback is highly Appreciated
on other Sheet
Cell Formulas
RangeFormula
A1:AJ1A1=IFERROR(INDEX(Sheet1!$A$2:$A$34,AGGREGATE(15,6,(ROW(Sheet1!$A$2:$A$34)-ROW($A$2)+1),COLUMNS($A2:A2))),"")


On the Same Sheet
Book1
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAGAH
1DerbyshireWest YorkshireDerbyshireDerbyshireWest YorkshireDerbyshireStaffordshireDerbyshireWest YorkshireGreater ManchesterWest YorkshireWest YorkshireWest YorkshireWest YorkshireStaffordshireSomersetCumbriaShropshireWest YorkshireCounty DurhamStaffordshireWest YorkshireLancashireNorthumberlandLancashireSouth YorkshireGreater ManchesterDerbyshireWest YorkshireCounty DurhamWest YorkshireLancashireWest Yorkshire 
2Derbyshire
3West Yorkshire
4Derbyshire
5Derbyshire
6West Yorkshire
7Derbyshire
8Staffordshire
9Derbyshire
10West Yorkshire
11Greater Manchester
12West Yorkshire
13West Yorkshire
14West Yorkshire
15West Yorkshire
16Staffordshire
17Somerset
18Cumbria
19Shropshire
20West Yorkshire
21County Durham
22Staffordshire
23West Yorkshire
24Lancashire
25Northumberland
26Lancashire
27South Yorkshire
28Greater Manchester
29Derbyshire
30West Yorkshire
31County Durham
32West Yorkshire
33Lancashire
34West Yorkshire
Sheet1
Cell Formulas
RangeFormula
A1:AH1A1=IFERROR(INDEX($A$2:$A$34,AGGREGATE(15,6,(ROW($A$2:$A$34)-ROW($A$2)+1),COLUMNS($A2:A2))),"")
 
Last edited:
Upvote 0
Here is an array formula that should work.
Must be entered with CTRL-SHIFT-ENTER. then drag across columns.

Sheet1
Book1
A
1Area
2Plant Floor
3Zinc Oven
4M Saw
5Saw
6Barrel Line
7Plant Floor
8Plant Floor
9Plant Floor
10Parking Lot
11Parking Lot
12Maint Tent
13Parking Lot
14Office
15Cell3
16Barrel Line
17Industrial
Sheet1


Sheet2
Cell Formulas
RangeFormula
A1:J1A1{=IFERROR(INDEX(Sheet1!$A$2:$A$17,SMALL(IF(FREQUENCY(MATCH(Sheet1!$A$2:$A$17,Sheet1!$A$2:$A$17,0),ROW(Sheet1!$A$2:$A$17)-ROW(Sheet1!$A$2)+1),ROW(Sheet1!$A$2:$A$17)-ROW(Sheet1!$A$2)+1),COLUMNS($A$1:A1))),"")}
Press CTRL+SHIFT+ENTER to enter array formulas surrounded with curly braces.
 
Upvote 0
Upvote 0
You could not have it in A1 as there has to be at least one cell to the left of the formula.
Could just use a stand-alone formula for the first result cell.

willow1985 1.xlsm
A
1Area
2Plant Floor
3Zinc Oven
4M Saw
5Saw
6Barrel Line
7Plant Floor
8Plant Floor
9Plant Floor
10Parking Lot
11Parking Lot
12Maint Tent
13Parking Lot
14Office
15Cell3
16Barrel Line
17Industrial
Sheet1


Cell Formulas
RangeFormula
A1A1=Sheet1!A2
B1:L1B1=IFERROR(INDEX(Sheet1!$A:$A,AGGREGATE(15,6,ROW(Sheet1!$A2:$A17)/ISNA(MATCH(Sheet1!$A2:$A17,$A1:A1,0)),1)),"")


If there could be blanks in the original list or you want to allow for a larger (unknown) range, the B1 formula above could be something like

Excel Formula:
=IFERROR(INDEX(Sheet1!$A:$A,AGGREGATE(15,6,ROW(Sheet1!$A2:$A100)/(ISNA(MATCH(Sheet1!$A2:$A100,$A1:A1,0))*(Sheet1!$A2:$A100<>"")),1)),"")
 
Upvote 0
Hi
Why not
VBA Code:
Sub test()
    Dim a As Variant, lr, i, x, s, k, itm
    a = Sheets("sheet1").Range("a2:a" & Cells(Rows.Count, 1).End(xlUp).Row)
    With CreateObject("scripting.dictionary")
        For i = 1 To UBound(a)
            If a(i, 1) <> "" Then
                If Not .exists(a(i, 1)) Then
                    .Add a(i, 1), 0
                End If: End If
        Next
      Sheets("sheet2").Cells(1, 1).Resize(, .Count) = .keys
    End With
End Sub
 
Upvote 0
Hi
Why not
VBA Code:
Sub test()
    Dim a As Variant, lr, i, x, s, k, itm
    a = Sheets("sheet1").Range("a2:a" & Cells(Rows.Count, 1).End(xlUp).Row)
    With CreateObject("scripting.dictionary")
        For i = 1 To UBound(a)
            If a(i, 1) <> "" Then
                If Not .exists(a(i, 1)) Then
                    .Add a(i, 1), 0
                End If: End If
        Next
      Sheets("sheet2").Cells(1, 1).Resize(, .Count) = .keys
    End With
End Sub

I have to say I do like the idea of using VBA but I could not get the above code to work for me right

VBA Code:
Sub test()
    Dim a As Variant, lr, i, x, s, k, itm
    a = Sheets("Log").Range("h2:h" & Cells(Rows.Count, 1).End(xlUp).Row)
    With CreateObject("scripting.dictionary")
        For i = 1 To UBound(a)
            If a(i, 1) <> "" Then
                If Not .exists(a(i, 1)) Then
                    .Add a(i, 1), 0
                End If: End If
        Next
      Sheets("Score Card").Cells(4, 3).Resize(, .Count) = .keys
    End With
End Sub

One sheet will have the data (Log) and the other is actually a score card (which is why I want the headers to score each area)

Would it also be possible for the VBA code to account for the year in cell A1 on sheet "Score Card"?

See the example below:

Safety Stats test.xlsx
ABCDEFGH
1First NameLast NameYearDateBuildingDivisionReportable/ non-reportableArea
220202020-09-24Non-ReportableBalancer
320202020-08-03ReportablePlant Floor
420202020-07-31Non-ReportablePlant Floor
520202020-06-30ReportableOvens
620202020-06-22ReportableShop
720202020-05-08ReportableSaw
820202020-04-24ReportableBarrel Line
920202020-04-08ReportablePlant Floor
1020202020-04-08Non-ReportablePlant Floor
1120202020-04-03ReportableParking Lot
1220202020-03-26ReportableMaint Tent
1320202020-03-26ReportableParking Lot
1420202020-03-09ReportableParking Lot
1520202020-03-04ReportableOffice
1620202020-02-24Non-ReportableLine
1720192019-06-11Non-ReportableIndustrial
1820182018-01-22ReportableStill Line
1920182018-01-16Non-ReportableStill Line
2020182018-03-22Non-ReportableShipping
Log
Cell Formulas
RangeFormula
C2:C20C2=YEAR(D2)


Safety Stats test.xlsx
ABCDEFGHIJKLM
12020
2Key Performance IndicatorOperationsAreas:
3TargetActualBalancerPlant FloorOvensShopSawBarrel LineParking LotMaint TentOfficeLine
4Safety (Employees)
5Reportable0110211113110
6Non-ReportableN/A41200000001
Score Card
Cell Formulas
RangeFormula
C5:C6C5=SUM(D5:AA5)
D5:M5D5=COUNTIFS(Log!$H:$H,'Score Card'!D3,Log!$C:$C,'Score Card'!$A$1,Log!$G:$G,'Score Card'!$A$5)
D6:M6D6=COUNTIFS(Log!$H:$H,'Score Card'!D3,Log!$C:$C,'Score Card'!$A$1,Log!$G:$G,'Score Card'!$A$6)
 
Upvote 0

Forum statistics

Threads
1,214,957
Messages
6,122,466
Members
449,086
Latest member
kwindels

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