?
Solved

MS Excel - Array MATCH type mismatch

Posted on 2011-09-14
4
Medium Priority
?
356 Views
Last Modified: 2012-05-12
Continuation of prior question -  "elegant" solution is generating at type mismatch on the match function of an array item within an array.  The goal is to build an new array for a report extracting the necessary data from various existing arrays in various column locations.  Also, the column that is being 'matched' is the first column in each of the arrays.

For x = 1 To RptRows
      ' (error is generated here)
      ID_Fnd = Application.Match(ReportArray(x, 1), Application.Index(ProdArray, , 1), 0)
      ReportArray(x, 7) = ProdArray(ID_Fnd, 2)
Next x

Watch is showing the following:
   ReportArray(x,1) -  variant/long
   Application.Index(ProdArray, , 1) -  variant/variant




0
Comment
Question by:uad
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 10

Expert Comment

by:SANTABABY
ID: 36537215
Could you please supply some surround code?
I'm curious to see how ReportArray and ProdArray are defined?
Would be great if you can attach a sample spreadsheet with the code & data where the problem occurs.
0
 
LVL 81

Accepted Solution

by:
zorvek (Kevin Jones) earned 2000 total points
ID: 36540061
I don't think the Application.Index function works on non Variant arrays. This should work:

    Dim x As Long
    Dim y As Long

    For x = 1 To RptRows
        For y = LBound(ProdArray, 1) To UBound(ProdArray, 1)
            If ProdArray(y, 1) = ReportArray(x, 1) Then
                ReportArray(x, 7) = ProdArray(y, 2)
                Exit For
            End If
        Next y
    Next x

Kevin
0
 

Author Comment

by:uad
ID: 36550158
I will try this and get back to you.

From a resource and speed perspective - rather than looping through to find ReportArray(x,1) value for all the rows,  would it make more sense to create a MatchArray with only the ID in the identical sequence as the ProdArray and still use the Match (& Index) as was first suggested?

    ReDim ProdArray(xRows, 2)
    Dim MatchArray(xRows)
    Range("A1").Select
    For x = 1 To SchCPRows
        ProdArray(x, 1) = ActiveCell.Value
        MatchArray(x) = Activecell.value
        ProdArray(x, 2) = ActiveCell.Offset(0, 1).Value
        ActiveCell.Offset(1, 0).Select
    Next x

    Dim ID_Fnd%
    For x = 1 To xRows
        ID_Fnd = Application.Match(ReportArray(x, 1), MatchArray, 0)
        ReportArray(x, 7) = ProdArray(ID_Fnd, 2)
    Next x
0
 
LVL 81

Expert Comment

by:zorvek (Kevin Jones)
ID: 36551443
You could do it that way. But looping through a few hundred elements of an array is pretty fast.

Kevin
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question