Formula to extract unique values as a horizontal list

willow1985

Well-known Member
Joined
Jul 24, 2019
Messages
886
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
 
How about
VBA Code:
Sub Willow()
   Dim Cl As Range
   Dim Dic As Object
   Dim Yr As Long
   
   Set Dic = CreateObject("scripting.dictionary")
   Dic.comparemode = 1
   Yr = Sheets("Score Card").Range("A1").Value
   With Sheets("Log")
      For Each Cl In .Range("H2", .Range("H" & Rows.Count).End(xlUp))
         If Cl.Offset(, -5).Value = Yr Then Dic(Cl.Value) = Empty
      Next Cl
   End With
   Sheets("Score Card").Range("D3").Resize(, Dic.Count).Value = Dic.Keys
End Sub
 
Upvote 0

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
How about
VBA Code:
Sub Willow()
   Dim Cl As Range
   Dim Dic As Object
   Dim Yr As Long
 
   Set Dic = CreateObject("scripting.dictionary")
   Dic.comparemode = 1
   Yr = Sheets("Score Card").Range("A1").Value
   With Sheets("Log")
      For Each Cl In .Range("H2", .Range("H" & Rows.Count).End(xlUp))
         If Cl.Offset(, -5).Value = Yr Then Dic(Cl.Value) = Empty
      Next Cl
   End With
   Sheets("Score Card").Range("D3").Resize(, Dic.Count).Value = Dic.Keys
End Sub

What could I add to this code to clear D3:AA3 any time there is a change to A1 and to re-run the above code?

I want it that every time the year is changed the Areas change as well and the old list removed.

Thank you again Fluff!
 
Upvote 0
How about
VBA Code:
Sub Willow()
   Dim Cl As Range
   Dim Dic As Object
   Dim Yr As Long
   
   Set Dic = CreateObject("scripting.dictionary")
   Dic.comparemode = 1
   Yr = Sheets("Score Card").Range("A1").Value
   With Sheets("Log")
      For Each Cl In .Range("H2", .Range("H" & Rows.Count).End(xlUp))
         If Cl.Offset(, -5).Value = Yr Then Dic(Cl.Value) = Empty
      Next Cl
   End With
   With Sheets("Score Card")
      .Range("D3:AA3").ClearContents
      .Range("D3").Resize(, Dic.Count).Value = Dic.Keys
   End With
End Sub
 
Upvote 0
How about
VBA Code:
Sub Willow()
   Dim Cl As Range
   Dim Dic As Object
   Dim Yr As Long
 
   Set Dic = CreateObject("scripting.dictionary")
   Dic.comparemode = 1
   Yr = Sheets("Score Card").Range("A1").Value
   With Sheets("Log")
      For Each Cl In .Range("H2", .Range("H" & Rows.Count).End(xlUp))
         If Cl.Offset(, -5).Value = Yr Then Dic(Cl.Value) = Empty
      Next Cl
   End With
   With Sheets("Score Card")
      .Range("D3:AA3").ClearContents
      .Range("D3").Resize(, Dic.Count).Value = Dic.Keys
   End With
End Sub

The code does not seem to be automatically running when the year is changed. I have to manually do it...
Any suggestions?
 
Upvote 0
Upvote 0
Last edited:
Upvote 0
@Dossfm0q
No idea how your sheet1 is setup, but with the values in col A only, the formula in post#16 will simply return the same value multiple times.
 
Upvote 0
@willow1985
Assuming that A1 is changed manually try
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   Dim Cl As Range
   Dim Dic As Object
   
   If Target.CountLarge > 1 Then Exit Sub
   If Target.Address(0, 0) = "a1" Then
      Set Dic = CreateObject("scripting.dictionary")
      Dic.comparemode = 1
      With Sheets("Log")
         For Each Cl In .Range("H2", .Range("H" & Rows.Count).End(xlUp))
            If Cl.Offset(, -5).Value = Target.Value Then Dic(Cl.Value) = Empty
         Next Cl
      End With
      Me.Range("D3:AA3").ClearContents
      Me.Range("D3").Resize(, Dic.Count).Value = Dic.Keys
   End If
End Sub
 
Upvote 0
@willow1985
Assuming that A1 is changed manually try
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   Dim Cl As Range
   Dim Dic As Object
  
   If Target.CountLarge > 1 Then Exit Sub
   If Target.Address(0, 0) = "a1" Then
      Set Dic = CreateObject("scripting.dictionary")
      Dic.comparemode = 1
      With Sheets("Log")
         For Each Cl In .Range("H2", .Range("H" & Rows.Count).End(xlUp))
            If Cl.Offset(, -5).Value = Target.Value Then Dic(Cl.Value) = Empty
         Next Cl
      End With
      Me.Range("D3:AA3").ClearContents
      Me.Range("D3").Resize(, Dic.Count).Value = Dic.Keys
   End If
End Sub
Unfortunately still nothing happens when I manually put in a different year in A1
 
Upvote 0
Did you put that in the Score Card sheet module?
 
Upvote 0

Forum statistics

Threads
1,214,617
Messages
6,120,541
Members
448,970
Latest member
kennimack

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