# Cell Range as function Parameter.

#### imtiaztariq

##### New Member
Hi guys,

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)

Last edited:

### 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
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
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
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

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
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.

#### imtiaztariq

##### New Member
Yeah that was the reason I figured it out thanks for your help 1,106,784
Messages
5,513,419
Members
408,952
Latest member
Dram16