Using stored variable in a formula

  • Thread starter Thread starter tc
  • Start date Start date
T

tc

Hi. i have managed to store the active sheet name in a variable. how
do i use this variable in a formula?
 
Here is what the formula look like in the spreadsheet

=SUM(Sheet2!A1:A5)

To generate this in VBA

MySheetName = "Sheet2"

Range("A1").formula = "=SUM(" & MySheetName & "!A1:A5)"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top