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

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand

aRandomHelper

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

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

Watch MrExcel Video

Forum statistics

Threads
1,132,803
Messages
5,655,400
Members
418,196
Latest member
kendocon

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