Cell Range as function Parameter.

imtiaztariq

New Member
Joined
Jul 22, 2010
Messages
4
Hi guys,

I am stuck in completing this task. It might be very simple but I am not good at VBA so please help.

I want to pass a Range of cells which needs to be given via prompt box into the following formula but I dont know how to do this.

This is the formula I have placed in my Excel sheet cell and I am reffering to this range in many other cells so What i need is that the user selects its range and it is placed it in every cell that contains this list.

=INDEX(LINEST('Regression Input Data'!$N$5:$N$19,'Regression Input Data'!$M$5:$M$19,1,1),5,1)

Would really appriciate your help thanks in advance
 
Last edited:

Some videos you may like

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.

Weaver

Well-known Member
Joined
Sep 10, 2008
Messages
5,196
What might be easier is if you define a named range which you can then include in all the relevant formulas. Then if the definition of this range is altered, all the formulas using it will alter too. Well, they'll still look the same, but give different results.
 

imtiaztariq

New Member
Joined
Jul 22, 2010
Messages
4
Can you please let me know how to pass a range name into this funtion and when needed to change how would it be.

thanks
 

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
If you know how to prompt a user for the range and place its address in A1 you can use:

=INDEX(LINEST(INDIRECT(A1),'Regression Input Data'!$M$5:$M$19,1,1),5,1)
 

imtiaztariq

New Member
Joined
Jul 22, 2010
Messages
4

ADVERTISEMENT

I have tried this thing now every thing seems to be working good here but the formula still does not work. WHere could be the error.



Dim InputCells As Excel.Range
Dim OutputCells As Excel.Range
On Error Resume Next
'Show input box to get range of cells that want to copy

Set InputCells = _
Application.InputBox(Prompt:="Block input cells/range", _
Title:="Copy Paste", Type:=8)

Set OutputCells = _
Application.InputBox(Prompt:="Select cell where you want paste it", _
Title:="Copy Paste", Type:=8)

ssr = Application.WorksheetFunction.Index(Application.WorksheetFunction.LinEst(InputCells, outputcelss, 1, 1), 4, 2)
Cells(1, 1).Value = ssr

a = Application.WorksheetFunction.Index(Application.WorksheetFunction.LinEst(InputCells, outputcelss, 1, 1), 2, 2)
Cells(2, 1).Value = a
 

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
There's a typo here:

ssr = Application.WorksheetFunction.Index(Application.WorksheetFunction.LinEst(InputCells, outputcelss, 1, 1), 4, 2)

To avoid such errors you should put Option Explicit at the top of your module.
 

Subscribe on YouTube

Watch MrExcel Video

Forum statistics

Threads
1,106,784
Messages
5,513,419
Members
408,952
Latest member
Dram16

This Week's Hot Topics

  • Sort code advice please
    Hi, I have the code below which im trying to edit but getting a little stuck. This was the original code which worked fine,columns A-F would sort...
  • SUMPRODUCT with nested If statement
    Hi everyone, Hope you're all well. I'm hoping someone will be able to point me in the right direction with a problem I'm having with a SUMPRODUCT...
  • VBA - simple sort is killing me!
    Hello all! This should be so easy, but not for me, apparently! I have a table of data that can be of varying lengths and widths. My current macro...
  • Compare Two Lists
    I have two Lists and I need to be able to Identify differences between them. List 100 comes from a workbook - the other is downloaded form the...
  • Formula that deducts points for each code I input.
    I am trying to create a formula that will have each student in my class start at 100 points and then for each code that I enter (PP for Poor...
  • Conditional formatting formula required for day of week and a value
    Hi, I have a really simple spreadsheet where column A is the date, column B is the activity total shown as a number and column C states the day of...
Top