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
 

Some videos you may like

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
35,643
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,443
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,089,560
Messages
5,408,981
Members
403,247
Latest member
prabutr28

This Week's Hot Topics

  • help please
    SORRY NOT ANY GOOD AT EXCEL SO HELP WOULD BE MUCH APPRECIATED this formula is in a sheet called ignore...
  • two formulas needed
    Hello, I'll try my best to explain this: First formula needed in Sheet1 cell A2: If Sheet1 cell B2 = Sheet2 cell B2 then return a 1. If not then...
  • Dynamic Counts
    Good afternoon, we are tidying up some data & the data seems to be growing quicker than we are tidying it up! What we confirm (by reviewing it...
  • Help Excel formula eliminate duplicate values and keep only 2 identical rows.
    as picture below column A has a duplicate value. but the values are not the same as the rule. sometimes 4 rows, sometimes 10 rows or 7 or 9...
  • Macro Compile Error Sub or Function not defined
    Hello, I am trying to run macros from a validation list, all macros have been created and run perfectly on there own but I'm getting a compile...
  • Last row combined with Current Region VBA
    I'm generally happy finding the last row of data through something like Lastrow = Cells(Rows.Count, "D").End(xlUp) but I don't always receive data...
Top