Excel: Copy all cell values from an entire sheet to a new sheet, sort and deduplicate into a single list of unique values

0

The data (all text values) I have is scattered across the sheet (multiple rows and columns with gaps inbetween) and it is all calculated using formulas

now I would like to make sure that I know what the exact list of distinct calculated values are

so here is what I need to do

  • copy values only to a new sheet
  • organise into a single list (column)
  • sort and de-duplicate

adolf garlic

Posted 2015-12-09T14:32:06.450

Reputation: 1 618

Welcome to superuser. Please share what have you tried so far and why that doesn't work. – Máté Juhász – 2015-12-09T15:44:07.010

Answers

1

Give something like this a try:

Sub Garlic()
   Dim cl As Collection, sh1 As Worksheet, sh2 As Worksheet
   Dim r As Range, K As Long, v As Variant, i As Long
   Set cl = New Collection
   Set sh1 = Sheets("Sheet1")
   Set sh2 = Sheets("Sheet2")
   K = 1

   On Error Resume Next
      For Each r In sh1.UsedRange
         v = r.Value
         If v <> "" Then
            cl.Add v, CStr(v)
         End If
      Next r
   On Error GoTo 0

   For i = 1 To cl.Count
      sh2.Cells(K, 1).Value = cl.Item(i)
      K = K + 1
   Next i

   sh2.Range("A1").CurrentRegion.Sort Key1:=Range("A1"), Order1:=xlAscending, Header:=xlNo, _
        OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
        DataOption1:=xlSortNormal

End Sub

Gary's Student

Posted 2015-12-09T14:32:06.450

Reputation: 15 540