I suggest iterating over each row in the range, extracting the values, generating the unique set, and repaste into the row.
The following function takes an array of values and returns the unique values in the array, using a Scripting.Dictionary
. Add a reference (Tools -> References...) to the Microsoft Scripting Runtime.
Function Unique(values As Variant) As Variant()
'Put all the values as keys into a dictionary
Dim dict As New Scripting.Dictionary, val As Variant
For Each val In values
dict(val) = 1
Next
Unique = dict.Keys
End Function
Then you can do the following:
Dim rng As Range, row As Range
Set rng = ActiveSheet.UsedRange
For Each row In rng.Rows
Dim values() As Variant 'We need this to extract the values from the range, and to avoid passing in the range itself
values = row
Dim newValues() As Variant
newValues = Unique(values)
ReDim Preserve newValues(UBound(values, 2)) 'without this, the array will be smaller than the row, and Excel will fill the unmatched cells with #N/A
row = newValues
Next
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…