# Using variable in Median Formula

#### Davew01

##### New Member
I using the code below to select a starting row and column and an ending row and column. I then copy and paste the data in the next column to the right.

---------------------
ActiveSheet.Range(Cells(SR, SC), Cells(ER, EC)).Select ' Select active range
Selection.Copy
'Set A = ActiveSheet.Range.Select
ActiveCell.Offset(0, 1).Select
'Range.Cells(0,1)
'Range("I15").Select
Selection.PasteSpecial paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False ' Paste Scores
Application.CutCopyMode = False
---------------
I would next like to perform a Median calculation on the data in the new column using variables to designate the start and end of the median calculation.

Example:

ActiveCell.FormulaR1C1 = "=MEDIAN(Cells(SR, SC):Cells(ER, EC))"

Is it possible to do something like this?

DaveW

### Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Dave

Where are you setting the values of SR, SC, ER and EC?

Or are they named ranges?

Variable in Median Formula

Those variables come from another section of the program. They represent the starting row (SR) and column (SC) and ending row and column (ER & EC). I am working on a program that locates Tournament golf scores vs regular play scores. Once I separate the Tournament scores into a vertical list using a loop that detects the start of the list (SR,SC) I copy this list into a separate column. I then want to determine the Median of the new column of scores.

One of my problems is that I am new to Excel VBA and macros. I have a lot of data that is exported into a XLS format a GHIN (golf handicap) program that I have to dig through and sort into just Tournament scores for about 300 players. Once I have each player’s set of tournament score separated into a new column I need to determine the median of the scores, select the median and all scores below the median and then run another formula to calculate Tournament handicap indexes. Since the scores are separated into new columns on the fly or dynamically I believe I need to use a variable in the median formula since I do not know ahead of time what the individual ranges are for each range of scores to put into the median formula.

Dave

Replies
1
Views
295
Replies
3
Views
161
Replies
3
Views
87
Replies
3
Views
299
Replies
8
Views
709

1,219,892
Messages
6,150,800
Members
450,985
Latest member
Andynair7

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

### Which adblocker are you using?

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

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