Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Exxcel Chart Code throws 'Object doesn't support this property or method' error

Posted on 2011-03-15
3
Medium Priority
?
653 Views
Last Modified: 2012-05-11
In the code below,  how can I write this line so that it works: "If ActiveChart.SeriesCollection(1).DataLabel = 1 Then ..."   Right now it throws an 'Object doesn't support this property or method' error. I've tried a bunch of variations, but obviously not the right one! :-)

Thanks,
John

Dim dl As DataLabels
      Set dl = ActiveChart.SeriesCollection(1).DataLabels
        For i = 1 To dl.Count
            If dl.Count <= 3 Then
                ActiveChart.SeriesCollection(1).DataLabels.NumberFormat = "0.00%"
            Else
              If ActiveChart.SeriesCollection(1).DataLabel = 1 Then
                ActiveChart.SeriesCollection(1).DataLabels.NumberFormat = "0%"
              Else
                ActiveChart.SeriesCollection(1).DataLabels.NumberFormat = "0.0%"
              End If
            End If
        Next

Open in new window

0
Comment
Question by:gabrielPennyback
3 Comments
 
LVL 24

Expert Comment

by:jimyX
ID: 35144719
VBA is not really my game, so I am not too sure about this, but here I am:

1. Why there is a loop, I do not see you are using the counter "i" anywhere?
2. Only to give you more options to try ;-)

For i = 1 To ActiveChart.SeriesCollection(1).Points.Count
  if ActiveChart.SeriesCollection(1).Points(i).DataLabel.Characters.Text = 1 then
    ActiveChart.SeriesCollection(1).Points.Item(i).DataLabel.NumberFormat =  "0%"
...

or

  if ActiveChart.SeriesCollection(1).Points(i).DataLabel.Text = 1 then
...

or

  if ActiveChart.SeriesCollection(1).values(i) = 1 Then
...
0
 
LVL 43

Accepted Solution

by:
Saqib Husain, Syed earned 2000 total points
ID: 35144936
Try

If ActiveChart.SeriesCollection(1).DataLabels.Item(1).Text = 1 Then
0
 
LVL 1

Author Closing Comment

by:gabrielPennyback
ID: 35149917
Thanks, ssaqibh.

jimyx, I thought I had your second solution working, but then I tried it 3 times again and it didn't work. Pls forgive me if it does in fact work.

Thanks,
- John
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

963 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question