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

sitko

New Member
Joined
Apr 23, 2007
Messages
17
Hi,

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...
Code:
' (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")

    Charts.Add
    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
    ActiveChart.SeriesCollection(1).Select
    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
    ActiveChart.PlotArea.Select
    With Selection.Border
        .ColorIndex = 57
        .Weight = xlThin
        .LineStyle = xlContinuous
    End With
    Selection.Interior.ColorIndex = xlNone
 
Last edited:

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney

Watch MrExcel Video

Forum statistics

Threads
1,129,549
Messages
5,636,959
Members
416,952
Latest member
prakashkumar

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top