VBA insert formula into cell with special character containing ""

MBM2016

New Member
Joined
Jun 3, 2015
Messages
6
Okay, so I am expanding my vlookup criteria and I need to insert a "-" within a formula in A1 - (for code details please see this)

This is what I think my vba should look like:
Code:
wb1.ActiveSheet.[A1].Value = ("=VLOOKUP(" & cID & rID & "&" & [COLOR=#ff8c00]""-""[/COLOR] & LastCol & "," & map & "," & i & ",FALSE)")

yet my editor keeps changing it to this and it does not work:
Code:
wb1.ActiveSheet.[a1].Value = ("=VLOOKUP(" & cID & rID & "&" & [COLOR=#ff0000]"" - ""[/COLOR] & LastCol & "," & map & "," & i & ",FALSE)")

This is what I am trying to accomplish:
=VLOOKUP(A15&"-"&B15,'C:\Users\x165422\Desktop\New folder\[Reference.xlsx]Ref'!$A$1:$I$15,4,FALSE)

Does anyone know what I am doing wrong or how I should I approach this problem?


Thank you!
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
I think there is an ampersand missing in your VBA code.

Code:
"=VLOOKUP(" & cID & rID & "&" & ""-"" & LastCol & "," & map & "," & i & ",FALSE)"
"=VLOOKUP(" & cID & rID & "&""-""&" & LastCol & "," & map & "," & i & ",FALSE)"

The first string above is copied from your email (what you think it should look like) and the second line is what the string should be.
 
Upvote 0
Great, thank you Aaron Blood!! it worked, I didn't see how taking out
Code:
[COLOR=#333333]"&" [/COLOR][COLOR=#ff0000]&[/COLOR][COLOR=#333333] ""-"" [/COLOR][COLOR=#ff0000]&[/COLOR]
and adding the additional ampersand would do it.

I will keep this in mind
:), thanks again!
 
Upvote 0

Forum statistics

Threads
1,214,643
Messages
6,120,702
Members
448,980
Latest member
CarlosWin

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