VBA - Problem with adding variable to formula

WednesdayC

Board Regular
Joined
Nov 7, 2010
Messages
201
Office Version
  1. 2016
Platform
  1. MacOS
Hi All

Please can anyone help me.


I am trying to add 2 variables (strmonth and stryear) to a formula using VBA.

strmonth contains "DEC" and stryear contains "16"

The plan is to become a title for an email.

I have tried various permutations. Example

Code:
ActiveSheet.Cells(2, 6).FormulaR1C1 = "=RC[-3]" & strmonth & stryear

This doesn't work and no does anything else I have tried. I assume I need an & somewhere, but can't see how.

Many thanks in advance.


Regards

Wednesday
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
maybe:

Code:
ActiveSheet.Cells(2, 6).Value = Range("C2").Value & strmonth & stryear
 
Upvote 0
If you really want a formula, you'd need something like this:

Code:
ActiveSheet.Cells(2, 6).FormulaR1C1 = "=RC[-3]&""" & strmonth & stryear & """"
 
Upvote 0
If you really want a formula, you'd need something like this:

Code:
ActiveSheet.Cells(2, 6).FormulaR1C1 = "=RC[-3]&""" & strmonth & stryear & """"


Hi Rory

Thank you so much - just what I wanted.

Have a great Xmas.

Regards
Wednesday
 
Upvote 0
Glad to help, and merry Christmas to you too. :)
 
Upvote 0

Forum statistics

Threads
1,214,583
Messages
6,120,377
Members
448,955
Latest member
BatCoder

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