Transposing Column data into rows, with unique values only

stevedhawes

Board Regular
Joined
Sep 11, 2007
Messages
112
Morning Folks,

Hoping someone can help me this a problem, as ive not been able to find anything online to answer my query.

I currently have colour names on worksheet "a" range E3:S102, and i aim aiming to find a quick way to be able to query the values in these cells, and return only unique colours in a vertical list on worksheet "b" @ range a1.

I would like this to happen dynamically, for example when tab b is activated, if possible.

Any help gratefully received, as this one is really baffling me

Best
Steve
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Must be placed in code module for worksheet "b":

Code:
Private Sub Worksheet_Activate()

  Dim UniqueVals() As Variant
  Dim UniqueCount As Long
  Dim Exists As Boolean
  Dim Cell As Range
  Dim i As Long
  
  Me.Columns("A").ClearContents
  
  For Each Cell In ThisWorkbook.Worksheets("a").Range("E3:S102")
    Exists = False
    If UniqueCount > 0 Then
      For i = LBound(UniqueVals) To UBound(UniqueVals)
        If Cell.Text = UniqueVals(i) Then
          Exists = True
          Exit For
        End If
      Next i
    End If
    If Not Exists Then
      UniqueCount = 1 + UniqueCount
      ReDim Preserve UniqueVals(1 To UniqueCount)
      UniqueVals(UniqueCount) = Cell.Text
    End If
  Next Cell
  
  If UniqueCount > 0 Then
    Me.Range("A1").Resize(UniqueCount).Value _
      = Application.Transpose(UniqueVals)
  End If
  
  Me.Columns("A").AutoFit

End Sub
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,286
Members
452,631
Latest member
a_potato

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