I need both Datalabels to be visible...on this VBA created chart...


New Member
Apr 23, 2007

I'm trying to create a XY scatter chart in VBA in an excel sheet. When I manually create it, it creates it just fine, but for some reason, when I try to automate its creation, it doesn't include both values in the Datalabels, just the Y value (the value in the second column of data).

here is the code I use:

Thanks for any help you can offer...
' (NumBottles is passed in)

    Dim wb As Excel.Workbook
    Dim posSheet As Worksheet
    Dim NodeNum As Integer
    Dim ChartTitle As String

    Set wb = Application.ActiveWorkbook
    Set posSheet = wb.Sheets("Positions")

    ActiveChart.ChartType = xlXYScatter
    ActiveChart.SeriesCollection(1).Name = "Filler Head Positions"
    ActiveChart.SeriesCollection(1).XValues = posSheet.Range("N3:N" & NumBottles + 2)
    ActiveChart.SeriesCollection(1).Values = posSheet.Range("O3:O" & NumBottles + 2)
    ActiveChart.Location Where:=xlLocationAsObject, Name:="Positions"
    With ActiveChart
        .HasAxis(xlCategory, xlPrimary) = False
        .HasAxis(xlValue, xlPrimary) = False
    End With
    ActiveChart.Axes(xlCategory, xlPrimary).CategoryType = xlAutomatic
    With ActiveChart.Axes(xlCategory)
        .HasMajorGridlines = False
        .HasMinorGridlines = False
    End With
    With ActiveChart.Axes(xlValue)
        .HasMajorGridlines = False
        .HasMinorGridlines = False
    End With
    ActiveChart.HasLegend = False
     With ActiveChart.SeriesCollection(1) 'selection
        .HasDataLabels = True 'selection
        With .DataLabels
            .ShowValue = True
' I wonder if there is some way to force both values to be visible here
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlCenter
            .ReadingOrder = xlContext
            .Position = xlLabelPositionBelow
            .Orientation = xlHorizontal
        End With
    End With
    With Selection.Border
        .Weight = xlHairline
        .LineStyle = xlNone
    End With
    With Selection
        .MarkerBackgroundColorIndex = xlNone
        .MarkerForegroundColorIndex = xlAutomatic
        .MarkerStyle = xlCircle
        .Smooth = False
        .MarkerSize = 15
        .Shadow = False
    End With
    With Selection.Border
        .ColorIndex = 57
        .Weight = xlThin
        .LineStyle = xlContinuous
    End With
    Selection.Interior.ColorIndex = xlNone
Last edited:

Forum statistics

Latest member

Some videos you may like

This Week's Hot Topics

  • VBA (Userform)
    Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
  • List box that changes fill color
    Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
  • Remove duplicates and retain one. Cross-linked cases
    Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
  • VBA Copy and Paste With Duplicates
    Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
  • Macro
    is it possible for a macro to run if the active cell value is different to the value above it
  • IF DATE and TIME
    I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...