Solved

Creating custom data labels in a chartseries

Posted on 2013-01-23
3
364 Views
Last Modified: 2013-01-24
Please take a look at the attached workbook. I need to get my chart values from Row 4, but I want to get my data labels from Row 5.

How do I do that? Assuming thatI can have a custom label other than series, category or value.

Thanks,
John
Custom-Data-Labels.xlsx
0
Comment
Question by:gabrielPennyback
3 Comments
 
LVL 50

Accepted Solution

by:
Rgonzo1971 earned 250 total points
ID: 38813388
Hi,

Maybe you should use this

http://appspro.com/Utilities/ChartLabeler.htm

regards
0
 
LVL 18

Assisted Solution

by:krishnakrkc
krishnakrkc earned 250 total points
ID: 38813512
Hi

Put this code in the sheet module. (Right click on tab name > view code > paste the code there in the white pane)

I assume that the sheet has some formulas. The code will fire each time when a calculation happens in the sheet.

Option Explicit

Private Sub Worksheet_Calculate()
    
    Dim rngLabel    As Range
    Dim rngValue    As Range
    Dim i           As Long
    
    Set rngValue = Range("B9:P9")       '<< adjust to suit
    Set rngLabel = Range("B10:P10")     '<< adjust to suit
    
    Application.ScreenUpdating = 0
    For i = 1 To rngValue.Columns.Count
        With rngValue.Cells(1, i)
            .NumberFormat = """Wk """ & .Value & vbLf & """ " & Right(rngLabel.Cells(1, i).Value, 4) & """"
        End With
    Next
    Application.ScreenUpdating = 1
    
End Sub

Open in new window


Kris
0
 
LVL 1

Author Closing Comment

by:gabrielPennyback
ID: 38817055
Thank you for your solutions. They didn't quite address my actual situation but the two of you got me started in the right direction and I was able to come with a good solution. For what it's worth, this is what I ended up with.

Sub GetDataLabels()
Dim i As Long, Ln As Range
    ActiveSheet.ChartObjects("Chart 1").Activate
    ActiveChart.SetElement (msoElementPrimaryValueAxisShow)
    ActiveChart.ChartArea.Select
    ActiveChart.SeriesCollection(1).Values = "='Weeks Done'!$X$4:$AJ$4"
For i = 1 To 13
Set Ln = Sheets("Weeks Done").Cells(6, i + 23)
    ActiveChart.SeriesCollection(1).Points(i).HasDataLabel = True
    ActiveChart.SeriesCollection(1).Points(i).DataLabel.Text = _
        Left(Sheets("Weeks Done").Cells(5, i + 23), Ln) & vbLf & _
        Right(Sheets("Weeks Done").Cells(5, i + 23), Ln)
    ActiveChart.SeriesCollection(1).Points(i).DataLabel.Position = xlLabelPositionInsideEnd
Next i
    With ActiveChart.Axes(xlValue)
        .MinimumScale = [Lo]
        .MaximumScale = [Hi]
        .MinorUnitIsAuto = True     '.MajorUnit = [XAxisMajor]
    End With
ActiveChart.Axes(xlValue, xlPrimary).Delete
[A1].Select
End Sub

Thanks,
John
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Drop Down List with Unique/Distinct Values (Part II - ComboBox or ListBox and Data Validation List Bonus!) David Miller (dlmille) Intro This article focuses on delivering unique, sorted lists to list objects (e.g., ComboBox, ListBox) and Dat…
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

829 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