Inserting a string in a macro line to create a formula for a coulmn

Bill_Biggs

Well-known Member
Joined
Feb 6, 2007
Messages
1,216
I have a column that a macro create selects to insert a formula in. The formula is like this:

=IF(OR(AL2={variable}),"Yes","No")

It places this fomula in AM2 but the column can vary so I am having to create a formula to plug in to the column. So This is the line from the macro that is supposed to do that:

ActiveCell.FormulaR1C1 = _
"=IF(OR(RC[-1]={" & K & "}),""Yes"",""No"")"


Now in the {} I want to place a string variable, K, that give this fomula its value seeking objective.

However, when ever I try to run it, this string errs out with an app or objects error. How should I be writing this so that the formula can be placed with the particular string I need it to find?
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
What does K contain? This worked for me:

Code:
Sub Test()
    Dim K
    K = """a"",""b"""
    ActiveCell.FormulaR1C1 = _
        "=IF(OR(RC[-1]={" & K & "}),""Yes"",""No"")"
End Sub
 
Upvote 0
I missed a set of quotation marks in creating K. I saw how you put them in and realized my error. Thanks,
 
Upvote 0

Forum statistics

Threads
1,214,591
Messages
6,120,428
Members
448,961
Latest member
nzskater

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