Hi,
I'm tryin to find the best/fastest VBA method of find and listing unique value's. the first bit and end bit will be implementend in my current VBA, but basicly the idea is:
- A list of approx 8000 cases will have to be processed
- there will be around 100 unique values with variating counts
- the output will be inserted in another sheet and picked up in further analysis
- VBA because this will run weekly during a year with dynamic data, and i'd like to press a button and be done with it
anyway, this is the code i use now. This will cycle all cases in the current column and list the unique value's in sheet "unique" which will be added (plz note, i didn't include error handling if the sheet exists).
[pre]
[/pre]
I'm tryin to find the best/fastest VBA method of find and listing unique value's. the first bit and end bit will be implementend in my current VBA, but basicly the idea is:
- A list of approx 8000 cases will have to be processed
- there will be around 100 unique values with variating counts
- the output will be inserted in another sheet and picked up in further analysis
- VBA because this will run weekly during a year with dynamic data, and i'd like to press a button and be done with it
anyway, this is the code i use now. This will cycle all cases in the current column and list the unique value's in sheet "unique" which will be added (plz note, i didn't include error handling if the sheet exists).
[pre]
Code:
Sub findunique()
Dim LastRow As Integer, StartRow As Integer, CurColumn As Integer
Dim x As Integer, y As Integer, z As Integer
Dim UniqueArray() As Variant
Dim IsInArray As Boolean
LastRow = ActiveSheet.UsedRange.Rows.Count
StartRow = 2 'just in case you use headers
CurColumn = Selection.Column
y = 0
ReDim Preserve UniqueArray(y)
For x = StartRow To LastRow
IsInArray = False 'reset
For z = LBound(UniqueArray) To UBound(UniqueArray)
If Cells(x, CurColumn) = UniqueArray(z) Then IsInArray = True
Next z
If IsInArray = False Then
ReDim Preserve UniqueArray(y)
UniqueArray(y) = ActiveSheet.Cells(x, CurColumn)
y = y + 1
End If
Next x
ActiveWorkbook.Sheets.Add.Name = "Unique"
For x = LBound(UniqueArray) To UBound(UniqueArray)
ActiveSheet.Range("A" & x + 1) = UniqueArray(x)
Next x
End Sub