Automating Chart elements in vba routine

Showard27

Board Regular
Joined
Sep 5, 2005
Messages
155
I have a bar chart in Excel (2016) which derives its data from various places in a complicated spread sheet by the user selecting certain variables to show using a user form. If a set of data is shown or not is automated in excel by either collecting values, or setting all the values to 0.

Also when a set of data is populated (and therefore shown) the legend entry is formatted by the text build up routine.

Code:
Sub RanPop2()
ReDim POSarray(1 To DDepth)
    ' Debug.Print RanDate
    With Worksheets("RunningTotals")
        LastCol = .Cells(1, .Columns.Count).End(xlToLeft).Column
    End With
    With Worksheets("RunningTotals")
        With .Range(.Range("A1"), .Range("A1").Offset(0, LastCol))
            Set RanCol = .Find(What:=RanDate, LookAt:=xlWhole, MatchCase:=False, SearchFormat:=False)
                If Not RanCol Is Nothing Then
                ' Debug.Print rFind.Column
                    For I = 1 To DDepth
                        POSarray(I) = Worksheets("RunningTotals").Range("a2").Offset((YearOff + I), RanCol.Column)
                    Next I
                        Sheets("ChartByCount").FullSeriesCollection(1).Values = POSarray
                        Sheets("ChartByCount").FullSeriesCollection(1).Name = Format(RanDate, "mmm-yy")
                End If
        End With
    End With
End Sub
and when I want that series not to be shown this runs
Code:
Sub RanClr2()
ReDim POSarray(1 To 1)
        Sheets("ChartByCount").FullSeriesCollection(1).Values = POSarray
        Sheets("ChartByCount").FullSeriesCollection(1).Name = "=""Undefined"""
End Sub
the problem I have is that I want to insert the code into the routine to show or hide the specific legend entry for that particular series, but I cannot figure out how to do it. I suspect it has something to do with LegendEntry(n) but am struggling. currently they are invisible so think I may have inadvertently deleted them (individually) as the master series remains, but am not finding a route through this one.

I have also discovered that somehow in my code I have several index numbers for the same series, While this is not spoiling the running of the routine, I am confused why this is happening.

Any input at all would be greatly appreciated

S
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result

Forum statistics

Threads
1,224,749
Messages
6,180,725
Members
452,995
Latest member
isldboy

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
Back
Top