OneBigEgg
OneBigEgg

Reputation: 35

Excel VBA - Refer to a worksheet as a variable in an IF statement

In the following piece of VBA code, how do I replace the reference to the worksheet 'ContolPage' with the variable 'cPage'?

ActiveCell.FormulaR1C1 = "=IF(RC[5]="""","""",ControlPage!R[-13]C[-2])"

Thanks

Upvotes: 1

Views: 281

Answers (1)

Scott Craner
Scott Craner

Reputation: 152450

You need to remove any vba variable from the quotes and concatenate with &:

ActiveCell.FormulaR1C1 = "=IF(RC[5]="""","""",'" & cPage & "'!R[-13]C[-2])"

Upvotes: 1

Related Questions