Dynamic Regressions.

JamisonHowell

New Member
Joined
Jun 30, 2017
Messages
4
SO the issue I am having is that I need to create a macro that copies information into a new sheet and then runs a regression on that information. Sounds simple enough, right? So I recorded this Macro:
Sub h()
'
' h Macro
' h
'
' Keyboard Shortcut: Ctrl+h
'
Range(Selection,Selection.End(xlDown)).Select
Range(Selection,Selection.End(xlToLeft)).Select
Range(Selection,Selection.End(xlToLeft)).Select
Selection.Copy
Sheets.AddAfter:=ActiveSheet
Range("A2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,SkipBlanks _
:=False,Transpose:=False
Range("B2").Select
Application.Run"ATPVBAEN.XLAM!Regress", ActiveSheet.Range("$AA$2:$AA$430")_
, ActiveSheet.Range("$I$2:$K$430"),False, True, , "", False, False, _
False, False,, False
Sheets("Sheet2").Select
Sheets("Sheet2").Name = "REG-HS"
Sheets("Sheet1").Select
Sheets("Sheet1").Name = "HIDDEN HS"
Sheets("REG-HS").Select
Range("A1").Select
End Sub



However this only works when there are exactly 430 rows. I need this work regardless of how many rows there are, so I tried to make this dynamic by altering the code to :

' h Macro
' h
'
' Keyboard Shortcut: Ctrl+h
'
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToLeft)).Select
Range(Selection, Selection.End(xlToLeft)).Select
Selection.Copy
Sheets.Add After:=ActiveSheet
Range("A2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("B2").Select
Application.Run "ATPVBAEN.XLAM!Regress", ActiveSheet.Range("$AA$2:$AA$" & Range("AA" & Rows.Count).End(xlUp).Rows) _
, ActiveSheet.Range("$I$2:$K$" & Range("K" & Rows.Count).End(xlUp).Rows
), False, True, , "", False, False, _
False, False, , False
Sheets("Sheet2").Select
Sheets("Sheet2").Name = "REG-HS"
Sheets("Sheet1").Select
Sheets("Sheet1").Name = "HIDDEN HS"
Sheets("REG-HS").Select
Range("A1").Select
End Sub


But.... now it doesn't work. Anyone have any idea that might work?
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK

Forum statistics

Threads
1,223,244
Messages
6,170,976
Members
452,372
Latest member
Natalie18

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