pedie
Well-known Member
- Joined
- Apr 28, 2010
- Messages
- 3,875
It errors...using formula in vba
<TABLE style="WIDTH: 50pt; BORDER-COLLAPSE: collapse" border=0 cellSpacing=0 cellPadding=0 width=67><COLGROUP><COL style="WIDTH: 50pt; mso-width-source: userset; mso-width-alt: 2450" width=67><TBODY><TR style="HEIGHT: 13.5pt" height=18><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext 0.5pt solid; BACKGROUND-COLOR: #953735; WIDTH: 50pt; HEIGHT: 13.5pt; BORDER-TOP: windowtext 0.5pt solid; BORDER-RIGHT: windowtext 0.5pt solid" class=xl65 height=18 width=67>#NAME?</TD></TR></TBODY></TABLE>
and formula displays this way...=RANK('i1','i1':'I22')
actual formula= "=RANK(I1,$I$1:$I$22)"
<TABLE style="WIDTH: 50pt; BORDER-COLLAPSE: collapse" border=0 cellSpacing=0 cellPadding=0 width=67><COLGROUP><COL style="WIDTH: 50pt; mso-width-source: userset; mso-width-alt: 2450" width=67><TBODY><TR style="HEIGHT: 13.5pt" height=18><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext 0.5pt solid; BACKGROUND-COLOR: #953735; WIDTH: 50pt; HEIGHT: 13.5pt; BORDER-TOP: windowtext 0.5pt solid; BORDER-RIGHT: windowtext 0.5pt solid" class=xl65 height=18 width=67>#NAME?</TD></TR></TBODY></TABLE>
and formula displays this way...=RANK('i1','i1':'I22')
actual formula= "=RANK(I1,$I$1:$I$22)"
Code:
[FONT=Courier New]Dim lr as long[/FONT]
[FONT=Courier New]lr = Sheet4.Range("H" & Rows.Count).End(xlUp).Row[/FONT]
[FONT=Courier New]Sheet4.Activate[/FONT]
[FONT=Courier New] Range("J1:J" & lr).FormulaR1C1 = "=RANK(I1,$I$1:$I$" & lr & ")"[/FONT]