Consulting

Results 1 to 2 of 2

Thread: Need to modify a User Defined Function

  1. #1

    Need to modify a User Defined Function

    I'm a newbie with VBA. I've tried writing a user defined function :

    Public Function SplitNames(NamesCell As Range)
        Dim vecNames As Variant
        Dim cell As Variant
        Dim yourPcge As String
        Dim tmp As String
         
        vecNames = Split(NamesCell.Value, ",")
        For Each cell In vecNames
             
            yourPcge = "=IF(A5="","",IF(SUMPRODUCT(--($A$2:$A5&$F$2:$F5=A5&F5))=1,(20-H5)/20,(20-SUMIF($F$2:$F5,F5,$H$2:$H5))/20))"
            tmp = tmp & cell & " : " & yourPcge & " ; "
        Next cell
         
        SplitNames = Left$(tmp, Len(tmp) - 3)
    End Function
    Now in the line,

    yourPcge = "=IF(A5="","",IF(SUMPRODUCT(--($A$2:$A5&$F$2:$F5=A5&F5))=1,(20-H5)/20,(20-SUMIF($F$2:$F5,F5,$H$2:$H5))/20))"
            tmp = tmp & cell & " : " & yourPcge & " ; "
    The formula is actually an excel formula. How do I change it so that it fits into the user defined function and gives me the expected result?

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,445
    Location
    You don't give us much to go on, but perhaps it should be

    [vba]

    Public Function SplitNames(NamesCell As Range)
    Dim vecNames As Variant
    Dim cell As Variant
    Dim yourPcge As String
    Dim tmp As String

    vecNames = Split(NamesCell.Value, ",")
    For Each cell In vecNames

    yourPcge = "=IF(A5="","",IF(SUMPRODUCT(--($A$2:$A5&$F$2:$F5=A5&F5))=1,(20-H5)/20,(20-SUMIF($F$2:$F5,F5,$H$2:$H5))/20))"
    tmp = tmp & cell & " : " & Application.Evaluate(yourPcge) & " ; "
    Next cell

    SplitNames = Left$(tmp, Len(tmp) - 3)
    End Function[/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
  •