我拥有的数据(所有文本值)分散在工作表中(多行和多列,中间有间隙),并且全部使用公式计算
现在我想确保我知道不同的计算值的确切列表是什么
所以我需要做的是
- 复制仅限值到新工作表
- 整理成一个列表(列)
- 排序和去重
答案1
尝试一下这样的方法:
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