Add PERCENTRANK Function Via Macro Code With Range Variable Address

  • I hope I can make this clear.


    I have been doing great with VBA as long as I can express my cells and ranges using the Cells(i,j) format in my code. Recently I wanted to use some ready made functions in excel like AVG, PERCENTRANK, STDV, and I noticed that I can't get these functions to accept my ranges which are defined using the cells(i,j) format.


    Example:

    Code
    Set rng1 = Range(Cells(21, 7), Cells(40, 7))
        
        Cells(21, 8) = "=PERCENTRANK(G21:G40,G21)"


    works fine
    while


    Code
    Set rng1 = Range(Cells(21, 7), Cells(40, 7))
        
        Cells(21, 8) = "=PERCENTRANK(rng1,cells(21,7))"


    doesn't


    Anything that I'm missin?


    I'm very impressed with the help that I have been finding here and I'm sure this one will be no exception


    Thanks Folks

  • Re: Ranges In Vba


    Hi, marino,


    Code
    Set rng1 = Range(Cells(21, 7), Cells(40, 7))
    
    
    Cells(21, 8) = "=PERCENTRANK(" & rng1.Address & "," & Cells(21, 7).Address & ")"


    Ciao,
    Holger

  • Re: Rranges In Vba


    Code
    Cells(21, 8).Formula = "=PERCENTRANK(" & rng1.Address(False,False) & "," & Cells(21,7).Address(False,False) & ")"

    HTH


    Bob

  • Re: Rranges In Vba


    Hi Marino72
    You should be a little more careful on your spelling when posting a question
    I would check out this link
    http://www.ozgrid.com/VBA/vba-macros.htm[hr]*[/hr] Auto Merged Post Until 24 Hrs Passes;[dl]*[/dl]Wow you guys are quick, two post while I am searching help for the poster

    Jim
    "The problem with designing vba code completely foolproof is to underestimate the ingenuity of a complete fool."

  • Re: Rranges In Vba


    These super fast replies make me believe that the world is still a nice place to live.


    Many many thanks folks,


    Marino

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!