-
"So my X range would be A1:last row of E"
??!! So where is the Y range?
I don't know that the regression can handle an X (or Y) range on more than one column or row!
Points on a chart each have 2 parts, an X coordinate and a Y coordinate. No points are missing a coordinate, no points have 3 coordinates (it's not a 3D chart is it?). So I'd hazard a guess that the number of X coordinates should be the same as the number of Y coordinates, which means equal size ranges of the 2 columns being used for the X and Y ranges. If they are different sizes; let's say the bottom of column A was row 10 so the range for say the X-coordinates is A1:A10, and the bottom of row C is row 5 so the range for the Y coordinates is C1:C5, that's great, we have pairs of coordinates for the first 5 points. But which value pairs up with A6, A7 etc.? Blank cells? I don't know how the regression tool handles blanks, perhaps it calls them zeroes. That's absolutely fine if you want blank cells to be counted as zeroes but be aware that it will affect the regression. I somehow doubt you want that.
So as a general rule of thumb, for a 2D chart, you always have pairs of coordinates so it's best if those pairs have values you're sure to want included in the regression calculation (rather than having random blank values) and that there should be an equal number of X and Y coordinates.
This is why in my code suggestion I had the line:
lrA = Cells(Rows.Count, "A").End(xlUp).Row
to find the bottom cell with anything in it in column A and the line:
lrC = Cells(Rows.Count, "C").End(xlUp).Row
to find the bottom cell with anything in it in column C.
To my mind (to anyone's actually), if these values were different then you wouldn't have a pair of coordinates for each point. So I had to use a row number which was the same for both column A and C, which gave rise to the line:
lr = Application.Max(lrA, lrC) 'or Min?
which takes the larger of the two values and puts it into lr, with the intention of using it for both X and Y ranges (Columns A and C) for the regression calculation.
Note the comment I made on the same line:
'or Min? I expect the x and y have to have the same number of values?
Since I plumped for max, then there would be some blank cells in one of the ranges - more fool me, I should have gone for min, that way there'd be no blanks at the bottom of either column that I didn't know how the regression tool handled. I did pose that question in the comment.
Now you've introduced columns B, D and F. I haven't the foggiest what part they play. If you're plotting column A against column F then you've correctly got
lr = Application.Max(lrA, lrF)
(although I would seriously consider using Min)
so in your line:
Application.Run "ATPVBAEN.XLAM!Regress", ActiveSheet.Range("F1:F" & lr), ActiveSheet.Range("A1:A" & lrE), False, True, 95, ActiveSheet.Range("P1"), False, False, False, False, ActiveSheet.Range("X3"), False
there is every chance the X and Y ranges are not the same size, and this is what I think the line should look like:
Application.Run "ATPVBAEN.XLAM!Regress", ActiveSheet.Range("F1:F" & lr), ActiveSheet.Range("A1:A" & lr), False, True, 95, ActiveSheet.Range("P1"), False, False, False, False, , False
This is hard work.
I'm going to test whether Application.displayAlerts=False will work for suppressing the overwriting question.
edit:
It doesn't.
You can always clear the area just before the regression line, something like:
Range("M1:U21").Clear
p45cal
Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules