Consulting

Results 1 to 9 of 9

Thread: Can you use the min & average function with cells and not ranges?

  1. #1

    Can you use the min & average function with cells and not ranges?

    hey guys, i am having trouble again, this time it is with excel's built in mid and average function, i need them to use the cells property as opposed to the range property, so i can loop through them... is there a way to do this? or can you do that with the range? attached is my files for my code.. any help would be appreciated. thanks

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Something like
    [vba]Private Sub cmdCalculate_Click()
    Dim LR As Long, i As Long
    LR = Cells(Rows.Count, 1).End(xlUp).Row
    For i = 2 To LR
    Cells(i, 3) = Application.Average(Cells(i, 4).Resize(, 5))
    Next
    End Sub

    [/vba]
    or
    [VBA]Private Sub cmdCalculate_Click()
    Dim LR As Long
    LR = Cells(Rows.Count, 1).End(xlUp).Row
    Range(Cells(2, 3), Cells(LR, 3)).FormulaR1C1 = "=AVERAGE(RC[1]:RC[5])"
    End Sub

    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    awesome now how would i take out the lowest value and calculate the average after taht?

  4. #4
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Are you wanting cell formulae or results?
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  5. #5
    well i want to make it so that it loops through and finds the lowest mark, then takes out that lowest mark and calculates the average after the lowest mark is taken out

  6. #6
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    I understood that, but are you looking for formuale or results to be entered on the spreadsheet?
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  7. #7
    i want the results in the cells

  8. #8
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    [vba]Range(Cells(2, 3), Cells(LR, 3)).FormulaR1C1 = _
    "=(SUM(RC[1]:RC[5])-MIN(RC[1]:RC[5]))/4"

    [/vba]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  9. #9
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Private Sub cmdCalculate_Click()
    Dim LR As Long
    LR = Cells(Rows.Count, 1).End(xlUp).row
    ActiveCell.Value = ActiveSheet.Evaluate( _
    "AVERAGE(IF(A1:A" & LR & "<>MIN(A1:A" & LR & "),A1:A" & LR & "))")
    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

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