Formula will not transfer into VBA

Src016

New Member
Joined
May 21, 2019
Messages
10
Hi All!

I am trying to put this worksheet function =IFERROR(VLOOKUP(SUBSTITUTE(E2,"/","-"),Master!$E:$E,1,FALSE),VLOOKUP(E2*1,Master!$E:$E,1,FALSE))

Into some VBA code that just drops the formula into a cell and copies it down the length of the data set. For some reason it is throwing me a 'type mismatch' error.

This is the code I am trying to drop the formula into:

Range("J1").Select ActiveCell.FormulaR1C1 = "Name"
Range("J2").Select
ActiveCell = "=IFERROR(VLOOKUP(SUBSTITUTE(E2,"/","),Master!$E:$E,1,FALSE),
VLOOKUP(E2*1,Master!$E:$E,1,FALSE))"

Selection.AutoFill Destination:=Range(Cells(2, 10), Cells(LastRowOAQ, 10)), Type:=xlFillDefault

Any ideas would be a huge help!

Thanks
 

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.
Try this

Code:
Sub MM1()
Range("J1").Value = "Name"
Range("J2:J" & LastRowOAQ).Formula = "=IFERROR(VLOOKUP(SUBSTITUTE(E2,"" / "","" - ""),Master!$E:$E,1,FALSE),VLOOKUP(E2*1,Master!$E:$E,1,FALSE))"
End Sub
 
Upvote 0
Hi Michael,

I just tried the above formula in the suggested code and it gave me a compile error: Syntax error. It is highlighting the last closed parenthesis and saying expected end. Any ideas?
"=IFERROR(VLOOKUP(SUBSTITUTE(E2,"" / "","" - "")

Thank you for the help!
 
Upvote 0
Sorry if LastRowOAQ is zero, you will get an error.
It may have helped if you had posted ALL the code !!
The code provided works fine for me.
 
Last edited:
Upvote 0
How have you declared LastRowOAQ ?
The 2 lines between Sub and End Sub where to be copied into YOUR code, not used independantly !
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,323
Messages
6,124,244
Members
449,149
Latest member
mwdbActuary

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