VBA Express Forum  




Go Back   VBA Express Forum > VBA Code & Other Help > Excel Help
     Feedback     
Register FAQ Members Arcade Knowledge Base Training Articles Consulting

Reply
 
Thread Tools Display Modes
Old 09-30-2009, 12:29 PM   #1
TSmith

 
Joined: Nov 2008
Posts: 10
Kb Entries: 0
Articles: 0
Solved: Regression Analysis macro

I am working on automating a regression analysis for our field staff but I am running into a problem referencing the cell range for the regression. Essentially, I have a pre-made form that the sales staff fills out and then runs one of two macros depending upon what type of regression analysis is desired. These macros populate the data form that is the base of the regression analysis. This form could have anywhere from 1 to 88 entries. I am trying to find the last cell used (yLast) in the named range and by using an offset set the xLast cell. I can find the last y value cell and get the offset to the xLast cell but when I try to use these as a reference in the regression code, I get an "application or object defined error.

Here is the code:


Code:
Private Sub CommandButton1_Click() 'code to run regression analysis Dim yFirst As Range Dim xFirst As Range Dim yEnd As Range Dim xEnd As Range Dim yRng As Range Dim xRng As Range With Range("RegRng") Set yEnd = .Cells(.Cells.Count).End(xlUp) End With Set xEnd = yEnd.Offset(0, -1) Set yFirst = Sheets("Data Summary").Cells(10, 5) Set xFirst = Sheets("Data Summary").Cells(10, 4) 'code to run regression - This is where the error occurs Application.Run "ATPVBAEN.XLA!Regress", ActiveSheet.Range("$e$10:$E$" & yLast), _ ActiveSheet.Range("$d$10:$d$" & xEnd), False, False, , "Analysis", False, False _ , False, True, , False ActiveSheet.ChartObjects("Chart 1").Activate ActiveChart.ChartArea.Select ActiveChart.Location Where:=xlLocationAsNewSheet, Name:="Chart1" Sheets("Data Summary").Select ActiveWindow.ScrollRow = 1 Range("G10").Select ActiveCell.FormulaR1C1 = "=SUM(Analysis!R17C2+RC[-3]*Analysis!R18C2)" Range("G10").Select Selection.AutoFill Destination:=Range("G10:G99"), Type:=xlFillDefault Range("G10:G99").Select End Sub

Any help would be greatly appreciated.

Tim

Local Time: 04:10 PM
Local Date: 05-22-2013
Location:

 
Reply With Quote Top
Old 09-30-2009, 12:57 PM   #2
Dr.K

 
Joined: Jun 2007
Posts: 150
Kb Entries: 0
Articles: 0
Is there a specifc reason why you are using the 'Application.Run' syntax?

VBA:
Application.Run "ATPVBAEN.XLA!Regress", ActiveSheet.Range("$e$10:$E$" & yLast), _ ActiveSheet.Range("$d$10:$d$" & xEnd), False, False, , "Analysis", False, False _ , False, True, , False
VBA tags courtesy of www.thecodenet.com

I'm pretty sure that if you want to pass Objects to a subroutine, you need to call it as a VBA Sub.

VBA:
Regress [Range Object], [Range Object], False, False, , "Analysis", False, _ False, False, True, , False
VBA tags courtesy of www.thecodenet.com

Local Time: 05:10 PM
Local Date: 05-22-2013
Location:

 
Reply With Quote Top
Old 09-30-2009, 03:19 PM   #3
Paul_Hossler

 
Joined: Apr 2007
Posts: 2,084
Kb Entries: 0
Articles: 0
I don't see where you're putting a value into yLast. I think you meant yEnd?

VBA:
Range("$e$10:$E$" & yLast)
VBA tags courtesy of www.thecodenet.com

Actually, it does not seemed to be Dim-ed. Did you use Option Explicit at the top of your module?

That still won't work, since yEnd is a Range. Your probably want yEnd.Row since you're making a address (string)

VBA:
Range("$e$10:$E$" & yEnd.Row)
VBA tags courtesy of www.thecodenet.com

will give something like Range("$e$10:$E$1000")


Paul

Local Time: 05:10 PM
Local Date: 05-22-2013
Location:

 
Reply With Quote Top
Old 10-02-2009, 05:58 AM   #4
TSmith

 
Joined: Nov 2008
Posts: 10
Kb Entries: 0
Articles: 0
Dr. K

To answer your question, the syntax for the regression came from a recorded macro. I took this as a shortcut.

Local Time: 04:10 PM
Local Date: 05-22-2013
Location:

 
Reply With Quote Top
Old 10-02-2009, 06:00 AM   #5
TSmith

 
Joined: Nov 2008
Posts: 10
Kb Entries: 0
Articles: 0
Solved Regression Macro

Paul

Thanks. That did the trick. Sometimes the answer lies in the basics and I get wrapped up in the code and forget the simple things.

Tim

Local Time: 04:10 PM
Local Date: 05-22-2013
Location:

 
Reply With Quote Top
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -7. The time now is 02:10 PM.


Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Copyright © 2004 - 2012 VBA Express