+ Reply to Thread
Results 1 to 4 of 4

Custom Function not calculating properly

  1. #1
    Registered User
    Join Date
    09-10-2006
    Posts
    7

    Custom Function not calculating properly

    Hi,

    I have this custom function that Sums certain cells accross all worksheets that have a name tarting with "PC". This works well accept that it is not calculating the decimal points. For example, the total should read 122.49 but instead reads 123.00. Below is a copy of the custom function:

    Function SumSheets(strCl As String)


    Application.Volatile
    Dim ws As Worksheet
    Dim x As Long
    For Each ws In ThisWorkbook.Worksheets
    If Left(ws.Name, 2) = "PC" Then
    x = x + ws.Range(strCl)
    End If
    Next
    SumSheets = x
    End Function

    Does any one know how to adjust this function to calculate properly?

    Thanks

  2. #2
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,393
    Long is an extended integer data type. DIM'med as such, x can only hold integers, and, thus, your function only returns integers. Perhaps you intended to DIM x as Single or Double.

  3. #3
    Valued Forum Contributor
    Join Date
    06-16-2006
    Location
    Sydney, Australia
    MS-Off Ver
    2013 64bit
    Posts
    1,394
    Yes, change x as long to x as double

  4. #4
    Registered User
    Join Date
    09-10-2006
    Posts
    7
    That worked well thanks!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1