VBA Not Interpreting Single Quotes Correctly

Mayanwolfe

New Member
Joined
Jun 5, 2013
Messages
27
Hello,

As part of a larger macro, I'm trying to input a formula into a range of cells. This formula does an indirect lookup of a worksheet name as a tab name, and therefore requires single quotes. However, VBA keeps trying to interpret the first single quote as a comment, and therefore commenting out the rest of the formula. I've tried using Chr(39) instead, but it still gives me run time error 1004. How can I reformat this formula to make it work within the macro, and still paste correctly into the cell range?

=IFERROR(IFNA(VLOOKUP(E11,INDIRECT("'"&$D11&"'!"&"$E$10:$S$120"),15,FALSE),VLOOKUP(E11,INDIRECT("'"&$D11&"'!"&"$D$10:$S$120"),16,FALSE)),0)

Thank you for any help. :)
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
You have to double up any " marks that are part of the actual formula string:

Code:
.Formula = "=IFERROR(IFNA(VLOOKUP(E11,INDIRECT(""'""&$D11&""'!""&""$E$10:$S$120""),15,FALSE),VLOOKUP(E11,INDIRECT(""'""&$D11&""'!""&""$D$10:$S$120""),16,FALSE)),0)"
 
Upvote 0
Can you please post the code that you are using to insert the formula?

Beaten2it
 
Last edited:
Upvote 0
Thanks Rory! That did it. I had already tried the double quotes thing also, but I put them in the wrong place. Now I understand how to do it properly! I really appreciate your help.
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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