Throwing an error in excel series, no idea why (1 Viewer)

emorris1000

Registered User.
Local time
Yesterday, 19:58
Joined
Feb 22, 2011
Messages
125
Got a real strange one here. I'm sure its something obvious, but I can't figure it out.

I have a graph in excel I am building (from access). Here's the basic code:

Code:
xlbook.Charts.Add
xlbook.ActiveChart.ChartType = xlXYScatter

RemoveUnwantedSeries xlbook  
'custom function that strips all of the garbage series vba adds automatically, works fine

Set xlSeries = xlbook.ActiveChart.SeriesCollection.NewSeries
 
'this is the code of interest
xlSeries.Name = xlsheet.Range("N1")
xlSeries.Values = xlsheet.Range("J4:J36")
xlSeries.XValues = xlsheet.Range("B4:B36")

Now, this works fine, but it uses explicit cell references which I don't like (since the length won't always be to J36). I would prefer to use my "lastrow" variable, which I use all over this module. The code I started with, which throws an error, is this:

Code:
With xlSeries
    .name = xlsheet.range("N1")
    .Values = xlsheet.Range(xlsheet.Cells(4, 10), xlsheet.Cells(Lastrow - 2, 2))  'throws an error
    .XValues = xlsheet.Range(xlsheet.Cells(4, 2), xlsheet.Cells(Lastrow - 2, 2)) 'throws an error
End With

I've checked the "lastrow" variable and it has the correct value, but every time I run this I get an application/object error (1004).

This is pretty basic stuff, so its really aggravating that I can't see where I screwed up.... help me with your better eyes.
 

emorris1000

Registered User.
Local time
Yesterday, 19:58
Joined
Feb 22, 2011
Messages
125
EVERY TIME I have one of these stupid errors I spend 2 hours staring at it and getting nowhere. Then I finally break down and post onto here. Then the glaring error SMACKS me in the face and I feel like quite the idiot.

I'm going from column 10 to column 2 in the .values range.

DERP
 

Users who are viewing this thread

Top Bottom