Getting a mismatch error trying to extract a row from a 2D array

RawlinsCross

Active Member
Joined
Sep 9, 2016
Messages
437
In what I thought would be a fairly straight forward operation, I'm getting stumped with an error. I have a table on a worksheet that I have registered under a NamedRange. I simply want to push each row to a Variant variable in turn. Easy right? Clearly I'm missing something.

VBA Code:
Private Sub RemoveDuplicateWORows()

Dim lFirst As Long, lLast As Long, i As Long
Dim vTable() As Variant
Dim vRow() As Variant
Dim wSht As Worksheet
Dim rRange As Range

Set wSht = ThisWorkbook.Worksheets("Data")
Set rRange = wSht.Range("rngData")

vTable = rRange.value

'Get first and last array positions
lFirst = LBound(vTable, 1)
lLast = UBound(vTable, 1)

For i = lFirst To lLast
    vRow = WorksheetFunction.Index(vTable, i, 0)  'mismatch error here
Next i

End Sub

The array vTable is a mixture of data types, string, date, numbers.
 
Must be a version thing, as the code works for me even with large strings.
I know that some functions don't like more than 255 characters, but didn't think index was one of them.
 
Upvote 0

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
After testing and retesting, and testing again - I finally got what I needed (although Rick, your function still failed under the same limitations as you hinted it might). It's been quite interesting learning this particular limitation even though it took all morning of wondering why my small test sets worked and my actual data failed.

Anyhow, thanks for all the feedback. The original range will never be more than a hundred or so rows - therefore I used a range-based approach. I step backwards as the last duplication will be the most-correct record.

VBA Code:
Private Sub RemoveDuplicateWORows()

Dim i As Long
Dim oDict As Object
Dim sWO As String

Set mwSht = ThisWorkbook.Worksheets("Data")
Set mrRange = mwSht.Range("rngData")
Set oDict = CreateObject("Scripting.Dictionary")

For i = mrRange.Rows.Count To 1 Step -1
    sWO = CStr(mrRange.Cells(i, 1).value)
    If Not oDict.Exists(sWO) Then
        oDict.Add sWO, ""
    Else
        mrRange.Rows(i).EntireRow.Delete
    End If
Next i

End Sub
 
Upvote 0

Forum statistics

Threads
1,216,118
Messages
6,128,939
Members
449,480
Latest member
yesitisasport

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