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

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.

BarryL

Well-known Member
Joined
Jan 20, 2014
Messages
1,436
Office Version
  1. 2019
Platform
  1. Windows
  2. MacOS
maybe:

Code:
ActiveSheet.Cells(2, 6).Value = Range("C2").Value & strmonth & stryear
 
Upvote 0

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
40,682
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
  2. MacOS
If you really want a formula, you'd need something like this:

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

WednesdayC

Board Regular
Joined
Nov 7, 2010
Messages
201
Office Version
  1. 2016
Platform
  1. MacOS
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

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
40,682
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
  2. MacOS
Glad to help, and merry Christmas to you too. :)
 
Upvote 0

Forum statistics

Threads
1,195,858
Messages
6,011,983
Members
441,661
Latest member
Pammie007

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
Top