Percent rank ignoring NA in VBA

Rookieeee

New Member
Joined
Aug 26, 2019
Messages
22
Hello guys,

I am ranking stocks using VBA rather than excel. In my dataset, I have 1 column of figures and some NAs, this I want to use percentrank to sort these numbers, ignoring NA. I can do is in excel using =PERCENTRANK.INC(IF(ISNUMBER(Column), column, ""), the target cell). However, it does not work in VBA when I copy it. Can you guys help me out?
Rich (BB code):
 monthlydata.Columns(4).Cells(i).Value = WorksheetFunction.PercentRank_Inc(IIf(IsNumber(monthlydata.Columns(3)), monthlydata.Columns(3), ""), monthlydata.Columns(3).Cells(i))

Thank you so much
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Hi & welcome to MrExcel
Easiest way to get the formula, is to put it into Excel, then start the macro recorder, select the cell & press F2 followed by enter. Turn off the recorder & you have the code.
 
Last edited:
Upvote 0
Hi & welcome to MrExcel
Easiest way to get the formula, is to put it into Excel, then start the macro recorder, select the cell & press F2 followed by enter. Turn off the recorder & you have the code.
Thank you for your help. The function in excel is not the same as what I use in VBA, it is just an example. In VBA, I have 'For' command, so VBA shows a syntax error when I use isnumber ().
Rich (BB code):
 For i = 1 To 151

    monthlydata.Columns(4).Cells(i).Value = PercentRank.INC(IIf(IsNumber(monthlydata.Columns(3)), monthlydata.Columns(3), ""), monthlydata.Columns(3).Cells(i))
 
    Next i
This command, particularly isnumber function is the bug, and I don't know how I can solve that.
 
Upvote 0
What code does the recorder produce?
 
Upvote 0
Rich (BB code):
Sub
Rich (BB code):
 Macro1()
Rich (BB code):
Rich (BB code):
'
' Macro1 Macro
'


'
    Range("T2").Select
    ActiveCell.FormulaR1C1 = _
        "=IF(ISNUMBER(RC[-1]),PERCENTRANK.INC(IF(ISNUMBER(R2C19:R1422C19),R2C19:R1422C19),RC[-1]),"""")"
    Range("T3").Select
End Sub
this is what it produces
 
Upvote 0
What code does the recorder produce?


Rich (BB code):
Rich (BB code):
Rich (BB code):
    Range("T2").Select
    ActiveCell.FormulaR1C1 = _
        "=IF(ISNUMBER(RC[-1]),PERCENTRANK.INC(IF(ISNUMBER(R2C19:R1422C19),R2C19:R1422C19),RC[-1]),"""")"
    Range("T3").Select
End Sub

this is what it produces, but it is only for the first cell of that column. I need to repeat this step for each cells
 
Upvote 0
In that case use
Code:
 Range("T2:T[COLOR=#ff0000]100[/COLOR]").FormulaR1C1 = _
        "=IF(ISNUMBER(RC[-1]),PERCENTRANK.INC(IF(ISNUMBER(R2C19:R1422C19),R2C19:R1422C19),RC[-1]),"""")"
Change the value in red to the last row you want the formula.
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

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