Stupid array problem

bensdb

New Member
Joined
Jan 24, 2014
Messages
18
I'm trying to pull a huge column of data into an array (500,000 rows), then remove some items that are direct duplicates of previous item, and then basically output it into a new column....

I have been going around in circles for hours now trying to do this and am not getting anywhere..

I figured making two arrays and then trying to transpose would be quickest method...Problem is that there is an application transpose limit for a dataset this large, so that doesnt work..

So I then have downloaded a transpose function to do it manually in VBA and that doesnt work either...


Code:
'uniquesDim arr() As Variant
Dim arr2() As Variant


Count = 1
arr = Range("B2:B" & lr)


ReDim arr2(1 To UBound(arr, 1), 0 To 1)


ws.Cells(2, 3).Value = ws.Cells(2, 2).Value


For i = LBound(arr, 1) + 1 To UBound(arr, 1)
    If arr(i, 1) = arr(i - 1, 1) Then
        'do nothing
    Else
        arr2(Count, 0) = arr(i, 1)
        Count = Count + 1
    End If
Next


ws.Range("C3:C" & Count + 2).Value = TransP(arr2)
Code:
Public Function TransP(var As Variant) As Variant  Dim outP() As Variant, i As Long, j As Long
  ReDim outP(LBound(var, 2) To UBound(var, 2), LBound(var, 1) To UBound(var, 1))
  For i = LBound(outP) To UBound(outP)
    For j = LBound(var) To UBound(var)
      outP(i, j) = var(j, i)
    Next
  Next
  TransP = outP
End Function
It outputs a column of "#N/A"'s...

Can anyone help me out here?

Thanks,

Ben
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
30,378
Office Version
365
Platform
Windows
Why not just use the "remove duplicates" facility on the data tab?
 

NdNoviceHlp

Well-known Member
Joined
Nov 9, 2002
Messages
2,313
Not sure if this helps? Dave
Code:
Function UniqueArr(InArr As Variant) As Variant
'returns array of unique values from inputted array
Dim Cnt As Integer, Cnt2 As Integer, Cnt3 As Integer, TempArr() As Variant
For Cnt = UBound(InArr) - 1 To LBound(InArr) Step -1
For Cnt2 = Cnt - 1 To 0 Step -1
If InArr(Cnt) = InArr(Cnt2) Then
GoTo below
End If
Next Cnt2
ReDim Preserve TempArr(Cnt3)
TempArr(Cnt3) = InArr(Cnt)
Cnt3 = Cnt3 + 1
below:
Next Cnt
UniqueArr = TempArr
End Function
 

Forum statistics

Threads
1,078,148
Messages
5,338,521
Members
399,240
Latest member
mominul2241

Some videos you may like

This Week's Hot Topics

Top