Avatar of akohan
akohan

asked on 

Activesheet instead of sheet1.

Hello group,

Instead of :

ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range(strSelectedRange), PlotBy:=xl3DColumn

I like to use:

ActiveChart.SetSourceData Source:=ACTIVESHEET.Range(strSelectedRange), PlotBy:=xl3DColumn

but it the VB compiler complains that this doesn't support the method !!!

How can I solve this limitation? maybe I'm using a WorkBook that doesn't have sheet1 or it is renamed. Then what?!

Regards,
ak
Microsoft OfficeMicrosoft ApplicationsMicrosoft Excel

Avatar of undefined
Last Comment
akohan
Avatar of p912s
p912s
Flag of United States of America image

What if you use this:
  ActiveWorkbook.ActiveSheet

Instead of this:
  ActiveSheet
Avatar of p912s
p912s
Flag of United States of America image

Or maybe:
  Selection.Address

Instead of:
  ACTIVESHEET.Range(strSelectedRange)
Avatar of p912s
p912s
Flag of United States of America image

>>strSelectedRange
Where does this come from?

If the above didn't help; can you post the rest of the code?
Avatar of akohan
akohan

ASKER



Hi,

Thanks but neither one works. It complains that "Object Doesn't support this property or method".

regards,
ak


Avatar of p912s
p912s
Flag of United States of America image

>> It complains that "Object Doesn't support this property or method".
Which is the same as your original error. Both are valid statements depending on how they're used.

Can you post your spreadsheet? You can upload here in a zipped format - http://ee-stuff.com/

Please post the link that is provided after the upload.
Avatar of byundt
byundt
Flag of United States of America image

Is this a chart embedded on a worksheet (in which case your code should work) or a separate chartsheet? If the latter, then the activesheet is a chartsheet, which has no range property.

I tested the following code with an embedded chart on a worksheet. I selected the chart, then ran the sub:

Sub ChangeChart()
Dim strSelectedRange As String
strSelectedRange = "H8:I9"
ActiveChart.SetSourceData Source:=ActiveSheet.Range(strSelectedRange), PlotBy:=xl3DColumn
End Sub
Avatar of JasonRubens
JasonRubens

What about

Dim mySheet as Worksheet
Set mySheet = activesheet

and then
ActiveChart.SetSourceData Source:=mySheet.Range(strSelectedRange), PlotBy:=xl3DColumn
ASKER CERTIFIED SOLUTION
Avatar of akohan
akohan

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of akohan
akohan

ASKER



Thanks!
Microsoft Excel
Microsoft Excel

Microsoft Excel topics include formulas, formatting, VBA macros and user-defined functions, and everything else related to the spreadsheet user interface, including error messages.

144K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo