How to reference a cell value in a different worksheet using sheet index numbers in VBA?

brianhf

New Member
Joined
Apr 20, 2021
Messages
2
Hello everyone,

I apologize if my question has already been answered, but I can't seem to find a solution to this issue.

I want a simple command/formula that reads a value in a specific cell in a different worksheet (within the same workbook) and then multiplies it with 24. I don't know the name of the worksheet in advance, so I'm trying to use the index number of the worksheet instead of the name of the worksheet.

When I use the 'Record macro' button on an existing worksheet (named 20-04-21) I will get this code, and it will work perfectly:

ActiveCell.FormulaR1C1 = "='20-04-21'!R[31]C[1]*24"

But how do I change it so that it reads the value from their index names Worksheet(2), Worksheet(3) etc. instead?

I've tried various things such as:

ActiveCell.FormulaR1C1 = "='WorkSheets(2)'!R[31]C[1]*24"
ActiveCell.FormulaR1C1 = "='Sheets(2)'!R[31]C[1]*24"
ActiveCell.FormulaR1C1 = "=WorkSheets(2)!R[31]C[1]*24"

None of them seem to work. What do I need to write instead?

Thanks in advance!
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.

aRandomHelper

Active Member
Joined
Jan 14, 2021
Messages
301
Office Version
  1. 2016
Platform
  1. Windows
Welcome to the forum!

Try:
VBA Code:
ActiveCell.FormulaR1C1 = "='" & Sheets(2).Name & "'!R[31]C[1]*24"
 

Forum statistics

Threads
1,140,917
Messages
5,703,168
Members
421,279
Latest member
emzy

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