+ Reply to Thread
Results 1 to 4 of 4

Can a function be modified to accept a divisor?

  1. #1
    Registered User
    Join Date
    01-11-2013
    Location
    SW Texas, USA
    MS-Off Ver
    Excel 2010
    Posts
    8

    Can a function be modified to accept a divisor?

    Hello,

    I asked for and received assistance for the creation of this function. It's #4:

    http://www.excelforum.com/excel-prog...html?p=3078063

    I've now modified the line: GetTens = CLng(Right(vVal \ 10, 1)) and created several new functions by changing the 10 to 1 or 100 or 1000. It's becoming confusing.

    Is it possible to place the divisor into the function call as something like:

    Function ADD_POSITIONS(Position,ParamArray cells()) As Double
    usage would be: =ADD_POSITIONS(10,A1,A2,A3,A4)

    instead of

    Function ADD_TENS(ParamArray cells()) As Double
    usage would be: =ADD_TENS(A1,A2,A3,A4)

    where the 10 would be the divisor? So the 10 would become 1 or 10 or 100 or 1000, etc. If this is possible, it would stop the confusion with using multiple versions of the same function.

    Thank you.

    Edited to include the original function:

    Function ADD_TENS(ParamArray cells()) As Double
    ' Generic Usage: =ADD_TENS(Cell_1,Cell_2,Cell_3,Cell_4)
    ' Usage in cell: =ADD_TENS(A1,A2,A3,A4)
    Dim n As Long
    Dim rCell As Range
    Dim dTemp As Double

    For n = LBound(cells) To UBound(cells)
    If TypeName(cells(n)) = "Range" Then
    For Each rCell In cells(n).cells
    dTemp = dTemp + GetTens(rCell.Value)

    Next rCell
    End If
    Next n
    ADD_TENS = dTemp

    End Function
    Function GetTens(vVal) As Long
    If IsNumeric(vVal) Then
    GetTens = CLng(Right(vVal \ 10, 1))
    End If
    End Function
    Last edited by Vba Novice; 01-12-2013 at 02:17 PM. Reason: Added original function as example.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Can a function be modified to accept a divisor?

    Perhaps this.
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    01-11-2013
    Location
    SW Texas, USA
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Can a function be modified to accept a divisor?

    Thank you very much Norie,

    Works great without any further confusion. I haven't yet figured out how to use code tags... Something new to learn...

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Can a function be modified to accept a divisor?

    Just select the code in the post and click the # symbol in the toolbar above.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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