简体   繁体   中英

rank function in vba syntax error

Range("AQ3").Formula = "=IF(ISNA(RANK(N3,Range("N3:N" & lastRow),0)),"",COUNTIF(Range("N3:N" & lastRow)" > "&N3)+1)"
Range("N3:N" & lastRow).filldown

Hi, for some reason I keep getting syntax error on the first line. I already defined last row in the previous section so there should be no error regarding that but i think it has to do something with general syntax. Can anyone help? Thanks

It is because of "N3:N" within the formula text. You haven't escaped the double quotes by using ""N3:N"" , for example.

There are general issues with the formula, however, which will stop this from working regardless. What you will require instead:

Range("AQ3").Formula = "=IF(ISNA(RANK(N3,N3:N" & lastRow & ",0)),"""",COUNTIF(N3:N" & lastRow & ", "">$N3"")+1)"
Range("N3:N" & lastRow).FillDown

You might also need to fill down Range("AQ3:AQ" & lastRow) – still, this won't throw a runtime error so long as lastRow is a valid integer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM