Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2011-03-15
3
Medium Priority
?
637 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

722 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