Type Mismatch error when using Index, and Match

silenti

New Member
Joined
Sep 20, 2010
Messages
5
System: Win XP
Excel: 2003

I´m just learning how to write Macros. What I want to do is get the corresponding category for certain fields (Mnemonic) these fields are grouped by countries. The categories are on column 3, whereas the mnemonics are grouped by countries in the rest of the columns.

The problem is I keep getting Type Mismatch error 13 in the line that has the Index and match functions. I already tried changing Mnemonic and IndicatorCat to strings to no avail.

Thanks,

Code:
Sub GenSeriesCategory()

Dim BbmRange As Range
Dim BbField As Variant
Dim WsNameB As String
Dim InitialRow As Long
Dim FinalRow As Long
Dim bbMCol As Long
Dim catRange As Range
Dim Mnemonic As Variant
Dim IndicatorCat As Variant

'Country name is the same name as the worksheet
WsNameB = ActiveSheet.Name

'Initial and final rows are taken from cells.
InitialRow = Sheet3.Range("B21").Value
FinalRow = Sheet3.Range("C21").Value
'Selects appropriate column to choose, where mnemonic is found
bbMCol = Application.Match(WsNameB, Range("'[List.xls]Mnemonics'!A2:Y2"), 0)
'Sets the ranges for the correct mnemonic country group and the fixed category group
Workbooks("List.xls").Worksheets("Mnemonics").Activate
    Set BbmRange = Workbooks("List.xls").Worksheets("Mnemonics").Range(Cells(InitialRow, bbMCol), Cells(FinalRow, bbMCol))
    Set catRange = Workbooks("List.xls").Worksheets("Mnemonics").Range(Cells(InitialRow, 3), Cells(FinalRow, 3))

ThisWorkbook.Activate
Range("B2").Select

    'This section generates all the categories for each of the Mnemonics

    For Each Mnemonic In Range("B5", Selection.End(xlToRight))
        IndicatorCat = Application.WorksheetFunction.Index(catRange, _
           Application.Match(Mnemonic, BbmRange, 0), 1)
        ActiveCell.Formula = IndicatorCat & ""
        ActiveCell.Offset(0, 1).Select
    Next
End Sub
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Just a guess...

Should

"Application.Match"

be

"Application.WorksheetFunction.Match"

??
 
Upvote 0
Already tried that. It works the same way. I´ve dropped the worksheetfunction since I´ve read it tends to be more unstable.
Thanks, Any other ideas?
 
Upvote 0
Or:
Rich (BB code):
IndicatorCat = WorksheetFunction.Index(catRange, _ 
WorksheetFunction.Match(Mnemonic.Value, BbmRange, 0), 1)
 
Upvote 0
That gives me a "Runtime 1004 error: Unable to get the Match Property of the WorksheetFunction class."
 
Upvote 0
I get the same Mismatch type error
The mismatch is occurring because you are asking for an exact match and there are cells in the range Mnemonic where there is no exact match. In that case, IndicatorCat is nothing.
Try this:
Code:
If Not WorksheetFunction.IsNa(WorksheetFunction.Match(Mnemonic.Value, BbmRange, 0)) Then
IndicatorCat = ... 'rest of code
End If
 
Upvote 0
Ignore my last post and try this:
Code:
 'This section generates all the categories for each of the Mnemonics
    For Each Mnemonic In Range("B5", Selection.End(xlToRight))
        On Error Resume Next
        IndicatorCat = WorksheetFunction.Index(catRange, _
        WorksheetFunction.Match(Mnemonic.Value, BbmRange, 0), 1)
        If Not IsError(InicatorCat) Then
            ActiveCell.Formula = IndicatorCat & ""
            ActiveCell.Offset(0, 1).Select
        End If
    Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,566
Messages
6,125,596
Members
449,238
Latest member
wcbyers

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