Consulting

Results 1 to 2 of 2

Thread: Excel 2013>VBA>Function>Average Visible Cells Horizontally

  1. #1
    VBAX Regular
    Joined
    May 2016
    Posts
    73
    Location

    Excel 2013>VBA>Function>Average Visible Cells Horizontally

    Hello,

    Is there a way of easily adapting this code to average visible cells horizontally? Thanks!

    Function Sum_Visible_Cells(Cells_To_Sum As Object)
    Dim cell As Object
    Dim Total As Double
    Application.Volatile
    For Each cell In Cells_To_Sum
    If (cell.Rows.Hidden = False) And (cell.Columns.Hidden = False) Then
    Total = Total + cell.Value
    End If
    Next
    Sum_Visible_Cells = Total
    End Function

  2. #2
    VBAX Regular
    Joined
    May 2016
    Posts
    73
    Location
    Here's what I did:

    Function AverageVisible(rng As Object)
        Dim rCell As Object
        Dim iCount As Integer
        Dim dTtl As Double
        
        Application.Volatile
        
        iCount = 0
        dTtl = 0
        
        For Each rCell In rng
        If (rCell.Rows.Hidden = False) And (rCell.Columns.Hidden = False) Then
        dTtl = dTtl + rCell
        iCount = iCount + 1
        End If
        
        Next
        AverageVisible = dTtl / iCount
        
    End Function

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
  •