Create a Chart using the Sheet Index Number not Sheet Name in VBA

DJBob

New Member
Joined
Nov 3, 2017
Messages
2
Hello,

I have got a Excel Spreadsheet which upon opening runs a macro which opens all .tsv files in a folder and creates them as Worksheets in Excel with the same name as the file. The name of the sheets are based on Dates and will be changing regularly, once it's over 8 weeks old it will be deleted.

However I need to create a chart across the different sheets, automatically without having to worry about sheet names.

Is there a way to do this?

What I have so far:

This works but when this data is deleted, it can't be used anymore and the new data will be missed.
ActiveChart.FullSeriesCollection(1).Values = "='20171013-LTPC01'!$C$3:$C$9"

I have tried creating a Function called SHEETNAME

Function SHEETNAME(b As Long) As String
SHEETNAME = Sheets(b).Name
End Function

ActiveChart.FullSeriesCollection(1).Values = "=SHEETNAME(1) '!$C$3:$C$9"

This causes an application or object defined error.

Has anyone got any ideas on how to solve this?

Thanks
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Re: How to create a Chart using the Sheet Index Number not Sheet Name in VBA

Hi. I cant test so this may work or may not:

Code:
ActiveChart.FullSeriesCollection(1).Values = "='" & SHEETNAME(1) & "'!$C$3:$C$9"
 
Upvote 0
Re: How to create a Chart using the Sheet Index Number not Sheet Name in VBA

Thank you very much worked perfectly.

I thought I had tried every combination of quotation marks, chucking them here, there and everywhere. Obviously except for this combination. Makes sense now.
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,252
Members
452,623
Latest member
Techenthusiast

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