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

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
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,223,893
Messages
6,175,246
Members
452,623
Latest member
cliftonhandyman

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