Consulting

Results 1 to 3 of 3

Thread: Select last 30 cells

  1. #1

    Select last 30 cells

    Hi,

    Could somebody please help me!

    I am trying to select the last 30 cells in a sheet.
    Example:
    =AVERAGE(B61:B90)
    By changing the value of B61:B90 to a variable range that it will only selecting the last 30 cells that have value.

    I included an attachment to illustrated better, I hope.

    Thank you for all your help in advance
    Julio
    Life is not as complicated as we think it is, we make it complicated.

    IF you can change it, then strive for excellence.
    IF not, then let it happen, don't worry about it and live a happier life.


    Let's Have Fun!
    Julio

  2. #2
    Site Admin VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,005
    Location
    You need to write a series of UDF's (user defined functions) in a standard module, here's teh first one for you:
    [VBA]
    Function AverageLast30()
    Dim Rng As Long, Rng1 As Long
    Rng = Range("B" & Rows.Count).End(xlUp).Row - 30
    Rng1 = Range("B" & Rows.Count).End(xlUp).Row
    AverageLast30 = Application.WorksheetFunction.Average(Range("B" & Rng & ":B" & Rng1))
    End Function
    [/VBA]you use it like this: instead of =Average(xx:xx) you type =AverageLast30() and it will work just like the normal function, if you need this for the other forumlae just follow the template i have given you!
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  3. #3
    The function works, the only thing is that it does not recalculate/update by itself when new values are enter, I have to go to in to the cell and hit enter to update it saving/exit re-start does not work neither F9 (recalculate formula), also if I has less than 30 values it does not seem to like it too much, my values start at B21, it gives me an error of circular formula.
    Any sugestions will be appriciated.
    Thank you
    Julio
    Life is not as complicated as we think it is, we make it complicated.

    IF you can change it, then strive for excellence.
    IF not, then let it happen, don't worry about it and live a happier life.


    Let's Have Fun!
    Julio

Posting Permissions

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