=INDIR|ECT not working where tab name created by macro

Mazbuka

New Member
Joined
Sep 23, 2018
Messages
23
Office Version
  1. 365
Platform
  1. Windows
Hope I can explain this alright.

I posted the below code to name the sheet tab as per contents of cell C2

Now in another sheet if I want to refer to the named sheet using =INDIRECT(A2&"!M28") where A2 has the name of the tab, it returns an error...however if I change A2 & the tab name to say xxxx it works.

Is this a known issue?

Sub RenameSheet()

Dim rs As Worksheet

For Each rs In Sheets
rs.Name = rs.Range("c2")
Next rs

End Sub
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
What is the name of the sheet?
Also if you are making the sheet name the same as C2 why is the formula looking at A2?
 
Upvote 0
On sheet 1, I'll list people's names in column a, so A2 will be Fluff
My sheet 2 will be named Fluff by the macro, pulling the name from cell C2
The INDIRECT function will be on Sheet1, looking at cell A2 (on sheet1) which says "fluff", to direct it to that worksheet.
 
Upvote 0
But what is the name of a sheet that doesn't work?
 
Upvote 0
In that case you need to add an apostrophe before & after the sheet name like
Excel Formula:
=INDIRECT("'"&A2&"'!M28")
 
Upvote 0

Forum statistics

Threads
1,215,220
Messages
6,123,698
Members
449,117
Latest member
Aaagu

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