.PlotArea.Width = 25 ...throwing really odd error.

JayCarr

New Member
Joined
Nov 7, 2012
Messages
35
So I have a block of code that is supposed to make a table, format it a bit, then add a whole bunch of series to it. Everything worked fine until I added the stuff under the " 'Lining up Plot Areas" section.

Code:
With infoGraph.Chart
        .ChartType = xlColumnClustered
        .ChartStyle = 42
        
        'Lining up Plot Areas
        .PlotArea.Format.Fill.Transparency = 1
        .PlotArea.Width = 25 'PROBLEM HERE
        .PlotArea.Left = 30
        .PlotArea.Top = 30
        .PlotArea.Width = 400
        
        
        Do Until .SeriesCollection.Count = 0
        .SeriesCollection(1).Delete
        Loop
        
        For j = 1 To SeriesCount 'jCount To jUpperBound
            For i = 1 To 9
                'This makes you skip every 3rd one
                If (i Mod 3 <> 0) Then
                    Set newSeries = .SeriesCollection.newSeries
                    With newSeries
                            .Values = ActiveSheet.Range(GraphData(i, j))
                            
                            If (i = 1 Or i = 2) Then
                                nameString = "2010"
                            ElseIf (i = 4 Or i = 5) Then
                                nameString = "2011"
                            Else
                                nameString = "2012"
                            End If
                            
                            nameString = nameString & " " & GraphData(10, j) & " "
                            
                            If (i = 1 Or i = 4 Or i = 7) Then
                                nameString = nameString & "O'Reilly Vol"
                            Else
                                nameString = nameString & "Market Vol"
                            End If
                            
                            .Name = nameString
                            
                            
                    End With
                End If
            Next i
        Next j
        
    End With
<problem line

Sorry, I feel like you can probably ignore most of that but you never know. Maybe someone will see something else I need to fix anyway (being new is so much fun...can't wait until I'm no longer clueless.)

The error is:
Code:
Run-time error '-2147467259 (80004005)'
Method 'Width' of object 'PlotArea' failed

Which seems self explanatory, but try as I might I cannot figure out what I am doing wrong with .width. I don't think it's the way I'm calling .PlotArea because the line
Code:
.PlotArea.Format.Fill.Transparency = 1

works just fine, and has for a while. But the first of the new lines I added in breaks everything.

Any ideas? Thanks in advance...

PS - Noticed I had the formatting before the actual creation of the plot area. So I moved it to after the creation of the plot area. No help, still broken. Will continue trying...
</problem>
 
Last edited:

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
For those who might have stumbled across this looking for an answer:

The problem seems (according to the Microsoft Database) that the Workbook is protected. This can be fixed by simply using
Code:
ActiveWorkbook.Unprotect

That being said, this worked to fix the problem listed above, but then the problem came back when I used an embedded .Axes statement later on. I'm moving it to it's own place to see if that fixes it...any suggestions are welcome. If that fixes it I'll post back as that would be the second fix of that same problem...
 
Upvote 0
I had a similar proiblem, but with .PlotArea.Height. I found that if I place a breakpoint at that line and then hit F5 to continue running, no error occurs. Very funny indeed...
And I also found that if I add the following line right above the .PlotArea.Height line, also no error occurs:
Code:
Debug.Print .PlotArea.Height

So in my case, this works:
Code:
Debug.Print .PlotArea.Height
.PlotArea.Height = 260

But after removing the first line, I get that error.

It seems like the first line somehow "activates" .PlotArea (in my case the plot area of a scatter chart).

But I'd like to know what's going on.
 
Upvote 0
After some more experimenting I found that this also works:
Code:
        With .PlotArea
            .Select
            .Height = 260
        End With

(the "With - End With" construction is not necessary, I just do that when doing more than one thing to the same object)
But I still don't know WHY it works. Or why it doesn't work without the .Select method.
 
Upvote 0

Forum statistics

Threads
1,223,901
Messages
6,175,277
Members
452,629
Latest member
SahilPolekar

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