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
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Why not just use the "remove duplicates" facility on the data tab?
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top