Consulting

Results 1 to 4 of 4

Thread: Sleeper: Summing & average by numberformat

  1. #1
    VBAX Mentor
    Joined
    Jun 2005
    Posts
    374
    Location

    Sleeper: Summing & average by numberformat

    attached is a workbook with the problem.
    a database of economic data year by year .each column of data is ccompanied by a column of growth ratio to the year befor formated in "0.00%".
    i am trying to build a UDF to deal with average growth rate ,as well as summig the data formated in "##,###.00"
    for instance - in sheet gdpf how can i get the average of data formated in "0.00%".
    thanks
    moshe

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by lior03
    attached is a workbook with the problem.
    a database of economic data year by year .each column of data is ccompanied by a column of growth ratio to the year befor formated in "0.00%".
    i am trying to build a UDF to deal with average growth rate ,as well as summig the data formated in "##,###.00"
    for instance - in sheet gdpf how can i get the average of data formated in "0.00%".
    thanks

    Function SumByFormat(rng As Range, Optional fmt As String = "0.00%")
    Dim cell As Range, amt As Double
        For Each cell In rng
            If cell.NumberFormat = fmt Then
                If IsNumeric(cell.Value) Then
                    SumByFormat = SumByFormat + cell.Value
                End If
            End If
        Next cell
    End Function

  3. #3
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    You could also consider using the line
    If cell.NumberFormat = ActiveCell.NumberFormat Then
    which could give you some added flexibility.
    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'

  4. #4

Posting Permissions

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