Consulting

Results 1 to 6 of 6

Thread: Formula to fill down used range

  1. #1
    VBAX Tutor
    Joined
    Jan 2020
    Posts
    204
    Location

    Formula to fill down used range

    Which calculates faster:

    Range("G2").FormulaR1C1 = "=IFERROR(RC[-2]/RC[-1],0)"                
                    With Sheets("comp")
                        .Range("G2").AutoFill .Range("G2:G" & .Cells(.Rows.Count, "A").End(xlUp).Row)
                    End With

    or

    Lastrow = Range("A" & Rows.Count).End(xlUp).Row
    
    Range("G2:G" & Lastrow).Formula ="=IFERROR(RC[-2]/RC[-1],0)"
    and why?

    Thank you!
    Last edited by jazz2409; 04-25-2020 at 08:00 PM. Reason: formatting

  2. #2
    VBAX Master paulked's Avatar
    Joined
    Apr 2006
    Posts
    1,007
    Location
    You can put in a timer to test it (and any other routines) quite simply:

    Sub Whatever()
        Dim tm as Double
        tm = Timer
    '
    ' Your code
    '
        Msgbox Timer - tm
    End Sub
    Semper in excretia sumus; solum profundum variat.

  3. #3
    VBAX Tutor
    Joined
    Jan 2020
    Posts
    204
    Location
    Quote Originally Posted by paulked View Post
    You can put in a timer to test it (and any other routines) quite simply:

    Sub Whatever()
        Dim tm as Double
        tm = Timer
    '
    ' Your code
    '
        Msgbox Timer - tm
    End Sub

    Ooohh so this is what they are doing.. I've seen threads with people saying this ran for x seconds .. Thanks! I'll try now

  4. #4
    VBAX Tutor
    Joined
    Jan 2020
    Posts
    204
    Location
    Quote Originally Posted by paulked View Post
    You can put in a timer to test it (and any other routines) quite simply:

    Sub Whatever()
        Dim tm as Double
        tm = Timer
    '
    ' Your code
    '
        Msgbox Timer - tm
    End Sub
    based on this, the second one works faster. Thank you!

  5. #5
    VBAX Master paulked's Avatar
    Joined
    Apr 2006
    Posts
    1,007
    Location
    You're welcome

    It's a handy thing to use when testing
    Semper in excretia sumus; solum profundum variat.

  6. #6
    VBAX Tutor
    Joined
    Jan 2020
    Posts
    204
    Location
    I actually included it in my project so I can check its performance anytime. Thank you.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •