Solved Run time error 13 type mismatch

GTretick

Member
Joined
Jul 29, 2015
Messages
49
Reaction score
0
Points
6
Location
Canada
Excel Version(s)
365
Hello,

I am trying to use a Match function in VBA to look up a cell position on another sheet.
I get a type mismatch error when doing so. I've tried changing various variables and cell formats but to no avail.
I can't tell exactly what variable or cell is offending the code.

I've attached a sanitized version of my workbook for reference.

Items highlighted in pink rely on other subroutines and formulas I've deleted from this version. They are there in case somehow their presence impacts my problem.

For context what I am ultimately trying to do is look in the grid in cells O3 to X12 in the "Background" tab then place the value (that corresponds between the dates in rows 3 and 4 in the "Monthly Outlook" tab) into each cell from N112 to Y112.

I'm building the routine is small steps.
1 Find the month my column represents > Mth = Month(Cells(4, mc))
2 Find the year my column represents > Yr = Year(Cells(4, mc))
3 Find what column in Background my year is located in > YrCol = Application.Match(Yr, Worksheets(Sheet3).Range(Cells(2, 15), Cells(2, 24)), 0)
**** this is my line I am having problems with *****
4 Find what row in Background my month is located in > not developed yet
5 Cross reference the row and column to grab the correct data > not developed yet

The macro is enabled by pressing the star in cell N1

Thanks for any consideration you might give to my issue.
 

Attachments

  • Grid Lookup.xlsm
    46.3 KB · Views: 2
Try this in N6 on Monthly Outlook

Code:
=INDEX(Background!$O$3:$X$14,MATCH(TEXT(N$3,"mmm"),Background!$N$3:$N$14,0),MATCH(YEAR(N$3),Background!$O$2:$X$2,0))
 
HI Bob.

Your suggestion is an Excel formula coded right onto the Excel worksheet. I'm trying to achieve a VBA solution that gets re-evaluated every time I run the routine.

Maybe for further context, all cells from rows 5 through X look at data elsewhere and are evaluated by other routines I've not included (to avoid getting bogged down in unnecessary detail), then refill, purge, sort etc. Line 112 is a special set of data that doesn't follow the pattern of the rest of the data hence the need for this particular separate routine.
 
The line should be this:

Code:
            YrCol = Application.Match(Yr, Sheet3.Range(Sheet3.Cells(2, 15), Sheet3.Cells(2, 24)), 0)
 
That did the trick! So it was a syntax issue. Thank you for Bob and Joe for taking the time to reply. Much appreciated.
 
Back
Top