Serving the Quantitative Finance Community

 
User avatar
brontosaurus
Topic Author
Posts: 0
Joined: May 10th, 2004, 8:33 pm

excel vba q on inserting an IF statement into a cell

December 24th, 2007, 2:33 pm

I've encountered a slightly odd problem:I want to use VBA code to insert an Excel IF statement into the first row of a certain column. The IF statement, conditions on certain word existing in a different column of the same row.The IF statement contains the symbols " " around the words I am looking for.my problem is that it seems that in order to insert the IF condition, I need to wrap it with " " and would thus use the following:="IF(RIGHT(A2,21)="MAC",LEFT(A2,LEN(A2)-21)&M2,A2)"to insert the formula into the cell.VBA is getting confused, and reading the second " as a closing of the statement I want to insert into cell, thus making the code meaningless.Any thoughts?Bronto
 
User avatar
Kanivan
Posts: 0
Joined: February 11th, 2005, 12:20 pm

excel vba q on inserting an IF statement into a cell

December 25th, 2007, 9:54 pm

this should work:="IF(RIGHT(A2,21)=""MAC"",LEFT(A2,LEN(A2)-21)&M2,A2)"
 
User avatar
brontosaurus
Topic Author
Posts: 0
Joined: May 10th, 2004, 8:33 pm

excel vba q on inserting an IF statement into a cell

December 26th, 2007, 10:43 am

thank you very much