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

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
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,215,523
Messages
6,125,321
Members
449,218
Latest member
Excel Master

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