How to paste a script in a given cell

Nahuster

New Member
Joined
Apr 22, 2016
Messages
33
Hello people,

I think I have a pretty dumb question but I can't figure it out.
I want to know why this works

Sheets("Template").Range("C37").Value = "=VLOOKUP(C36,RA!A2:B100,2,FALSE)"

and this doesn't

Sheets("Template").Range("C99").Value = "=LEFT(C4,FIND(" ",C4)-1)"

I guess it's because of the "" , but that's what has to go into the cell for the rest to work.

How should I phrase that?.
Again, in cell C99 I want the script to write this
=LEFT(C4,FIND(" ",C4)-1)


Thanks in advance.
Cheers!
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Try:

Sheets("Template").Range("C99").Value = "=LEFT(C4,FIND("" "",C4)-1)"

Quotes within quotes must be doubled for Excel to recognize them. If the quote is on an end, you could have 3 consecutive quotes: 2 for the interior quote, and 1 to terminate the string.

Hope this helps.
 
Upvote 0
Hello people,

I think I have a pretty dumb question but I can't figure it out.
I want to know why this works

Sheets("Template").Range("C37").Value = "=VLOOKUP(C36,RA!A2:B100,2,FALSE)"

and this doesn't

Sheets("Template").Range("C99").Value = "=LEFT(C4,FIND(" ",C4)-1)"

I guess it's because of the "" , but that's what has to go into the cell for the rest to work.

How should I phrase that?.
Again, in cell C99 I want the script to write this
=LEFT(C4,FIND(" ",C4)-1)
Quote marks on the outside of a text string tells VB that what is inside is text. VB cannot tell whether the internal quotes are text characters or your attempt to end the text string at that location. To get around this problem, quote characters need to be doubled up inside of the quote marks delineating a text string... VB assumes such doubled up quotes to represent a single quote character. Given that, your code line should be this...

Sheets("Template").Range("C99").Value = "=LEFT(C4,FIND("" "",C4)-1)"
 
Upvote 0
If the quote is on an end, you could have 3 consecutive quotes: 2 for the interior quote, and 1 to terminate the string.
The way I have explained this in the past is like this. Starting with the fact that quote marks must be doubled up inside of the outer quote marks that delineate a text string, consider this code line...

SomeVariable = "Beginning""End"

which would assign the text Beginning"End to the variable. Remove Beginning which leaves this...

SomeVariable = """End"

which is why there are three quotes when the quote mark is at the end of the text. Now, extending this one more time, remove End which leaves this...

SomeVariable = """"

which is why it takes four quote marks to represent a single quote mark character.
 
Last edited:
Upvote 0
THANK YOU VERY MUCH. That Worked! :)


Try:

Sheets("Template").Range("C99").Value = "=LEFT(C4,FIND("" "",C4)-1)"

Quotes within quotes must be doubled for Excel to recognize them. If the quote is on an end, you could have 3 consecutive quotes: 2 for the interior quote, and 1 to terminate the string.

Hope this helps.
 
Upvote 0

Forum statistics

Threads
1,214,376
Messages
6,119,175
Members
448,870
Latest member
max_pedreira

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