Range named using UDF and resultant problem using INDIRECT

tbablue

Active Member
Joined
Apr 29, 2007
Messages
488
Office Version
  1. 365
Platform
  1. Windows
Hi,

My workbook is essentially a datatable and numerous sheets, each with two charts on it. The charts are simple, formatted identically - but are populated using dynamic named ranges. Everytime I add more sheets, I need to manually create more dynamic named ranges to control each new graph.



I've a UDF that returns the corresponding sheetname of any cell that doesn't contain an error.

Function SheetName(rCell As Range, Optional UseAsRef As Boolean) As String
Application.Volatile
If UseAsRef = True Then
SheetName = "'" & rCell.Parent.Name & "'!"
Else
SheetName = rCell.Parent.Name
End If
End Function


When I use it like this in $A$1...

="'"&SheetName($A$1)&"'!"&"$AA$22"

...it behaves just as I expect and returns something like this...

'CPD5237FP Top Level - Full'!$AA$22

...so far, so good!


I thought I could be clever and use it within the INDIRECT function, escaping the need to declare explicit sheetnames in named ranges for charting.

e.g.
=OFFSET(INDIRECT(" ' "&SheetName($A$1)&" '! "&"$AA$22"),0,0,20,1)

The idea being that my UDF would operate in place of an explicitly declared sheetname and because the chartsheets are essentially set-out and formatted identically, one dynamic formula could be made to work regardless of the sheet it resides on. Make sense !?

However, when I input this formula into the name manager (Excel 2007) it doesn't work as anticipated. For example, copy and pasting the exact formula above becomes the following formula when you hit Enter...

=OFFSET(INDIRECT("'"&SheetName('Actual Sheet name here'!$A$1)&"'!"&"$AA$22"),0,0,20,1)

I don't want the RED cell refs (and they don't feature when I just use my UDF outside of INDIRECT) - but INDIRECT seems to incorporate them into the formula.

Am I barking up the wrong tree? Is there any work around that means I don't have to re-specify new named ranges for every new sheetname and chart?

Hopefully, this makes sense. ANy assistance gratefully rec'd.

Cheers
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type

Forum statistics

Threads
1,224,517
Messages
6,179,233
Members
452,898
Latest member
Capolavoro009

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