How to create variable cell ranges in formulas eg in Rank

IanPM

Board Regular
Joined
Dec 12, 2013
Messages
53
I have a rank formula that counts a variable range for evaluation. However the starting point is a fixed cell reference which is fixed to specific column. I want it to be variable based on find & offset functions as the excel sheet changes & therefore the range in the formula needs to move.

In below how do I change that code so that the starting cell & columns are complete variables?

Sub dural()
Dim N As Long
N = Cells(Rows.Count, "B").End(xlUp).Row
Range("A2:A" & N).Formula = "=rank(B2,B$2:B" & N & ")"

End Sub
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
How is this
Sub dural()
Dim N As Long
Dim myCol As Long

myCol = ActiveCell.Column

N = Cells(Rows.Count, myCol + 1).End(xlUp).Row
Range(Cells(2, myCol), Cells(N, myCol)).FormulaR1C1 = "=RANK(RC[1],RC[1]:R" & N & "C[1])"

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,599
Messages
6,120,447
Members
448,966
Latest member
DannyC96

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