ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Sheet Reference Syntax (https://www.excelbanter.com/excel-programming/368687-sheet-reference-syntax.html)

Jennifer

Sheet Reference Syntax
 
I'm pretty sure I've done this before, but can't recall the syntax...

I have a variable strDataSheetName that is a string and refers to the name
of a worksheet. I have it as a string variable, because the name of the
sheet I want to refer to has to do with the name of the sheet I am on.

How do I select this sheet using the variable name? See code below (this
syntax does not work)...

ActiveChart.SetSourceData Source:=Sheets("" &
strDataSheetName).Columns("A:F"), PlotBy:=xlColumns

Thanks!

Tom Ogilvy

Sheet Reference Syntax
 
worksheets(strDatasheetname).Select

--
Regards,
Tom Ogilvy


"Jennifer" wrote:

I'm pretty sure I've done this before, but can't recall the syntax...

I have a variable strDataSheetName that is a string and refers to the name
of a worksheet. I have it as a string variable, because the name of the
sheet I want to refer to has to do with the name of the sheet I am on.

How do I select this sheet using the variable name? See code below (this
syntax does not work)...

ActiveChart.SetSourceData Source:=Sheets("" &
strDataSheetName).Columns("A:F"), PlotBy:=xlColumns

Thanks!


Jennifer

Sheet Reference Syntax
 
It doesn't like that. I think I misstyped: not selecting, but getting data
from the sheet.

This works:

ActiveChart.SetSourceData Source:=Sheets("Sheet1").Columns("A:F"),
PlotBy:=xlColumns

But I want to refer to my variable instead of hardcoding the name.

"Tom Ogilvy" wrote:

worksheets(strDatasheetname).Select

--
Regards,
Tom Ogilvy


"Jennifer" wrote:

I'm pretty sure I've done this before, but can't recall the syntax...

I have a variable strDataSheetName that is a string and refers to the name
of a worksheet. I have it as a string variable, because the name of the
sheet I want to refer to has to do with the name of the sheet I am on.

How do I select this sheet using the variable name? See code below (this
syntax does not work)...

ActiveChart.SetSourceData Source:=Sheets("" &
strDataSheetName).Columns("A:F"), PlotBy:=xlColumns

Thanks!


Tom Ogilvy

Sheet Reference Syntax
 
if that works, then
s = "sheet1"
ActiveChart.SetSourceData Source:=Sheets(s).Columns("A:F"),
PlotBy:=xlColumns

should work in the same place as an example.

--
Regards,
Tom Ogilvy


"Jennifer" wrote:

It doesn't like that. I think I misstyped: not selecting, but getting data
from the sheet.

This works:

ActiveChart.SetSourceData Source:=Sheets("Sheet1").Columns("A:F"),
PlotBy:=xlColumns

But I want to refer to my variable instead of hardcoding the name.

"Tom Ogilvy" wrote:

worksheets(strDatasheetname).Select

--
Regards,
Tom Ogilvy


"Jennifer" wrote:

I'm pretty sure I've done this before, but can't recall the syntax...

I have a variable strDataSheetName that is a string and refers to the name
of a worksheet. I have it as a string variable, because the name of the
sheet I want to refer to has to do with the name of the sheet I am on.

How do I select this sheet using the variable name? See code below (this
syntax does not work)...

ActiveChart.SetSourceData Source:=Sheets("" &
strDataSheetName).Columns("A:F"), PlotBy:=xlColumns

Thanks!


Jennifer

Sheet Reference Syntax
 
Oh, duh. I had a different problem. Nevermind.

"Tom Ogilvy" wrote:

if that works, then
s = "sheet1"
ActiveChart.SetSourceData Source:=Sheets(s).Columns("A:F"),
PlotBy:=xlColumns

should work in the same place as an example.

--
Regards,
Tom Ogilvy


"Jennifer" wrote:

It doesn't like that. I think I misstyped: not selecting, but getting data
from the sheet.

This works:

ActiveChart.SetSourceData Source:=Sheets("Sheet1").Columns("A:F"),
PlotBy:=xlColumns

But I want to refer to my variable instead of hardcoding the name.

"Tom Ogilvy" wrote:

worksheets(strDatasheetname).Select

--
Regards,
Tom Ogilvy


"Jennifer" wrote:

I'm pretty sure I've done this before, but can't recall the syntax...

I have a variable strDataSheetName that is a string and refers to the name
of a worksheet. I have it as a string variable, because the name of the
sheet I want to refer to has to do with the name of the sheet I am on.

How do I select this sheet using the variable name? See code below (this
syntax does not work)...

ActiveChart.SetSourceData Source:=Sheets("" &
strDataSheetName).Columns("A:F"), PlotBy:=xlColumns

Thanks!



All times are GMT +1. The time now is 09:32 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com