Run-time error 13: Type Mismatch Error

VaYooper

New Member
Joined
Mar 12, 2015
Messages
31
I have this mismatch error occurring in the ActiveCell.Formula section that has been driving me crazy trying to figure out. It's the same one I use for all my various macro sheets but for osme reason this one is giving me problems. The cell is formatted as General and so is the data being pulled in. Am I missing something obvious? Thanks

VBA Code:
    Dim LastRow As String
   
    LastRow = Range("A" & Rows.Count).End(xlUp).Row
 
ActiveCell.FormulaR1C1 = _
    Range("N2:N" & LastRow).Formula = "=IF(ISERROR(VLOOKUP(RC[-5],Codes!C[-13]:C[-12],2,FALSE)),"" "",VLOOKUP(RC[-5],Codes!C[-13]:C[-12],2,FALSE))"[/B][/COLOR]
       
    Columns("N:N").Select
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
For that formula you need to use .FormulaR1C1, you also need to double=up on all the quotes inside the formula.
 
Upvote 1
Just a follow-up to what Fluff said, if you have trouble coming up exactly what the formula should look like, simply turn on your Macro Recorder and record yourself entering the formula into one of these cells. Then you can stop the Macro Recorder, and copy/paste the formula section of what you recorded to your code.
 
Upvote 0
Also the
VBA Code:
ActiveCell.FormulaR1C1 = _
part shouldn't be there, just...

VBA Code:
 Range("N2:N" & LastRow).FormulaR1C1 = "=IF(ISERROR(VLOOKUP(RC[-5],Codes!C[-13]:C[-12],2,FALSE)),"" "",VLOOKUP(RC[-5],Codes!C[-13]:C[-12],2,FALSE))"
Which would give the below in N2

Excel Formula:
=IF(ISERROR(VLOOKUP(I2,Codes!A:B,2,FALSE))," ",VLOOKUP(I2,Codes!A:B,2,FALSE))
I doubt though that you want the space in " "
 
Upvote 1
Solution
Also the
VBA Code:
ActiveCell.FormulaR1C1 = _
part shouldn't be there, just...

VBA Code:
 Range("N2:N" & LastRow).FormulaR1C1 = "=IF(ISERROR(VLOOKUP(RC[-5],Codes!C[-13]:C[-12],2,FALSE)),"" "",VLOOKUP(RC[-5],Codes!C[-13]:C[-12],2,FALSE))"
Which would give the below in N2

Excel Formula:
=IF(ISERROR(VLOOKUP(I2,Codes!A:B,2,FALSE))," ",VLOOKUP(I2,Codes!A:B,2,FALSE))
I doubt though that you want the space in " "
People tell me all the time about the space in there... its a muscle memory issue I have a hard time gettin rid of as that was how I would write it the first couple hundred times when I began writing formulas. :cool:
 
Upvote 0
Happy we helped you find a solution.

Btw in your original post you appear to be trying to use some custom formatting in the code (although missing the 1st part of the BB code tags) , if you want to custom format code then you need to use the RICH code tag rather than the VBA code tag for it to display correctly.
 
Upvote 0

Forum statistics

Threads
1,214,651
Messages
6,120,738
Members
448,988
Latest member
BB_Unlv

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