VBA Quotations

ExcelRoy

Well-known Member
Joined
Oct 2, 2006
Messages
2,540
Office Version
  1. 365
Platform
  1. Windows
Hi Guys,

I am having some problems in using the quotations in VBA

I need to generate the following

Code:
=IF(VP1_T_01=0,"","£" & VP1_T_01 & "m")

I have a very poor effort of

Code:
Cells(i, "G").Formula = """"=IF(VP1_T_0" & x & "=0,"""","£" VP1_T_0" & x &")""""

I know its the amount of quotations, but i just cant get the amount in the right places

Thanks
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Record a macro inserting the formula.
 
Upvote 0
Actually found this won't work as i had hoped

i need the "x" values in the code. How would i achieve that using the recorder?

Thanks
 
Upvote 0
In general,

o Replace each quote with double quotes

o Add single quotes at the beginning and end
 
Upvote 0
I have tried replacing the quotes with double quotes etc but still nothing?
 
Upvote 0
The rule is actually quite simple... one quote mark goes around the entire text constant (that tells VB what is inside is a text constant) and for each quote mark that is part of the text you just surrounded with quote marks, put an extra quote mark next to it so that there are two of them next to each other... remember, you double up each original quote mark that was part of the text (excluding the quote marks you added to tell VB that it was processing a text constant). For example, if this is your text...

The man said "Hello" to me.

it would become this...

"The man said ""Hello"" to me"

The purple ones were added to tell VB it was processing a text constant and the orange ones were where I doubled up the original quote marks.
 
Last edited:
Upvote 0
Hi Rick,

Thanks, but using this method, what am i doing wrong here

Code:
.Formula = "=IF(V_P1_T_0"" & x & ""=0"","""",""£"" & ""V_P1_T_0"" & x & ""m""& "")"
 
Upvote 0
Original:

=IF(VP1_T_01=0,"","£" & VP1_T_01 & "m")

Double the quotes:

=IF(VP1_T_01=0,"""",""£"" & VP1_T_01 & ""m"")

Add quotes at beginning and end

"=IF(VP1_T_01=0,"""",""£"" & VP1_T_01 & ""m"")"
 
Upvote 0
Hi shg,

Yes this works, but i need it to work with my value x in my last code

Thanks
 
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,827
Members
452,946
Latest member
JoseDavid

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