Solved

Data Labels in Excel Scatterplot

Posted on 2002-07-20
6
259 Views
Last Modified: 2007-12-19
I have a workbook with the X values in column A and the Y values in column B. Based on these values I have created a scatterplot of the data. Now, in column C I have the labels that I want to go with the data points. I want to get Excel to place these column C labels next to each point. But with the data labels option I can only select 'none', 'value' or 'data'. The first option is clear, the second gives me the Y value, and the third one gives me the X value as label next to the point. Is there a way to get the column C text as labels with my points?
0
Comment
Question by:FlorisMK
[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
6 Comments
 
LVL 44

Accepted Solution

by:
bruintje earned 50 total points
ID: 7166863
Hi FlorisMK,

grabbed this from another thread

-----------------------------------

Copy the macro below and paste it into a VBA module.
To run the macro, set up your data with the name of the data point before the x data (so instead of column C use column A for the data labels), select the data series on your plot, and run the macro.

Sub AttachLabelsToPoints()
 'Dimension variables.
 Dim xLabel, yValue As Variant
 Dim Counter As Integer, ChartName As Variant
 Dim SourceWorksheet As Variant, xvals As Variant, xcell As Variant
 'NAVAIR Changes
 Dim SeriesString As String, StringElement As String
 Dim PlotOrder As Integer, n As Integer, nchars As Integer
 SeriesString = ExecuteExcel4Macro("Get.Formula(Selection())")
 nchars = Len(SeriesString)
 For n = nchars To 1 Step -1
    StringElement = Mid(SeriesString, n, 1)
    If StringElement = "," Then Exit For
 Next n
 PlotOrder = Left(Right(SeriesString, nchars - n), nchars - n - 1)
 'End NAVAIR changes
 'Disable screen updating while  the  subroutine  runs.
 Application.ScreenUpdating = False
 'Store the name of the active  chart  in  "ChartName".
 ChartName = ActiveChart.Name

 'Store the definition of the first series in "xVals".
 xvals = ActiveChart.SeriesCollection(PlotOrder).Formula

 'These lines extract the name of the source worksheet from xvals.
 SourceWorksheet = Left(xvals, InStr(1, xvals, "!") - 1)
 SourceWorksheet = Right(SourceWorksheet, Len(SourceWorksheet) - _
 InStr(1, SourceWorksheet, "("))
 If Left(SourceWorksheet, 1) = "," Then
 SourceWorksheet = Right(SourceWorksheet, Len(SourceWorksheet) - 1)
 End If

 'Replace the actual source worksheet name with "xlsheet" so that the
 'searches that follow will work correctly if the worksheet name
 'contains commas.
 xvals = Application.Substitute(xvals, SourceWorksheet, "xlsheet")

 'More processing of the  xvals  name.
 xvals = Right(xvals, Len(xvals) - InStr(1, xvals, ","))

 'If the chart is using "assumed" x-values ...
 If Left(xvals, 1) = "," Then

 '...show an alert message.  NOTE: the following two lines should be
 'entered as a single line.
 MsgBox "This xy (scatter) chart is using assumed x values." & " The macro
cannot continue."

 'Exit the subroutine if "assumed" x values are in use.
 Exit Sub
 End If

 'More processing of the  xvals  name.
 xvals = Left(xvals, InStr(1, xvals, ",") - 1)

 'Put the original source worksheet name back into xvals, replacing
 '"xlsheet".
 xvals = Application.Substitute(xvals, "xlsheet", SourceWorksheet)
 

 'Initialize a counter.
 Counter = 1

 'For each cell in the range xvals ...
 For Each xcell In Range(xvals)
 'Get the value of the label next to the current x-value.
 xLabel = xcell.Offset(0, -1).Value
 yValue = xcell.Offset(0, 1).Value
 'Check if cell has a value
 If xLabel <> "" Then
 If yValue <> "" Then
 'Attach a label to the current data point in the chart.  Note:
 'enter the following two lines as a single line.
 ActiveChart.SeriesCollection(PlotOrder).Points(Counter). _
 HasDataLabel = True
 'Put the text ("DataPointl", for example) into the attached label.
 'Note: enter the following two lines as a single line.
 ActiveChart.SeriesCollection(PlotOrder). _
 Points(Counter).DataLabel.Text = xLabel
 End If
 End If
 'Increment the counter.
 Counter = Counter + 1
 Next xcell                'loop until all done
 Application.ScreenUpdating = True
 'Make sure nothing in the chart is selected.
 Application.ExecuteExcel4Macro "SELECT("""")"
 End Sub

-----------------------------------

be carefull didn't test it yet

HAGD:O)Bruintje
0
 
LVL 2

Author Comment

by:FlorisMK
ID: 7167776
It works! It even has some superfluous XL4-macro running code, but in general it works like a charm. So do you get the points or whoever answered the first thread? (-:
0
 
LVL 44

Expert Comment

by:bruintje
ID: 7170222
uh think that is not possible the first thread was on a user group on the internet :)

so i will gladly take care of them
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 13

Expert Comment

by:cri
ID: 7171224
Get the Chart Labeler from http://www.bmsltd.co.uk/MVP/Default.htm . Besides you having it in Menu|Tools for all future workbooks, if it allows you to format the labels at definition time.
0
 
LVL 2

Author Comment

by:FlorisMK
ID: 7172627
Just in time, cri! The code works well, so points for that, but a nifty addin with menu command is even better, so you are stealing half Bruintjes points for this.

I'll see to a points split through CS - thanks on behalf of my friend who asked the question of me and now thinks I'm her hero... (-:
0
 
LVL 1

Expert Comment

by:Computer101
ID: 7172910
Points reduced for split.  Comment from expert accepted as ansswer

Computer101
E-E Moderator
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
Cancel future meetings from user mailboxes in Office 365 using Remove-CalendarEvents
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…

628 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