PDA

View Full Version : [SOLVED:] Need Help with this macro, please! need to return unque values from within range



estatefinds
09-16-2016, 08:15 AM
So I have numerical Data in columns A B C D E.
I want to be able to run the macro; in which I would have the range ; the range from A1 to E15000 for example and return the unique values found within this range and return these unique values to column F; starting in row 1.

mikerickson
09-16-2016, 11:02 AM
By unique values, do you mean those valuees that appear once?
Or all values with duplicates removed?
From 1 1 2 3 3 4
Do you want 1 2 3 4 or 2 4 ?

estatefinds
09-16-2016, 11:21 AM
good question. ok this might help so for what ever range of data I have it will have any of the numbers 1 to 35 in the range. so if it appears once it will record it if it appears twice three times four times etc. it will record it. so say for instance the number 1 was recorded in column F and it sees duplicates in the range it wont record it again cause it already recorded it already. so its returning the values found within that range.

estatefinds
09-16-2016, 01:01 PM
let me know if you have any more questions on this Thank you:)

estatefinds
09-16-2016, 05:44 PM
Hi, how is it coming along?

mikerickson
09-16-2016, 06:10 PM
It takes some time to do anything with 75,000 of anything, but you might try this.
I exceeded the requirements in that the result is sorted.


Sub trial()
Dim rngInput As Range, arrInput As Variant
Dim arrOutput() As Variant
Dim oneElement As Variant
Dim i As Long, j As Long, Size As Long, pointer As Long

With Sheet1
Set rngInput = Range(.Cells(Rows.Count, 1).End(xlUp), .Range("E1"))
End With

Size = WorksheetFunction.CountA(rngInput)
arrInput = rngInput.Value
ReDim arrOutput(1 To Size, 1 To 1)

For i = 1 To UBound(arrInput, 1)
For j = 1 To UBound(arrInput, 2)
oneElement = arrInput(i, j)
If IsNumeric(oneElement) Then
If i = Application.Match(oneElement, rngInput.Columns(j), 0) Then
arrOutput(WorksheetFunction.Rank(oneElement, rngInput, 1), 1) = oneElement
End If
End If
Next j
Next i

pointer = 0
For i = 1 To UBound(arrOutput, 1)
If arrOutput(i, 1) <> vbNullString Then
oneElement = arrOutput(i, 1)
pointer = pointer + 1
arrOutput(i, 1) = vbNullString
arrOutput(pointer, 1) = oneElement
End If
Next i

Range("g1").Resize(pointer + 1, 1).Value = arrOutput

End Sub

estatefinds
09-17-2016, 01:06 AM
I just ran it on the small example and it runs great!!!! I ll test it on the big data. Thank you Very much!!! great work!!!:)

estatefinds
09-17-2016, 05:12 PM
It worked great on the large data!! Thanks again!!!!