Consulting

Results 1 to 3 of 3

Thread: lookup formula to sum percent

  1. #1

    VLOOKUP formula to sum percent

    Hello, I have been trying to figure out how to do this for two weeks and I'm lost.... Lets start off With my TEST sheet and Employee 1. What I need it to do is if I enter an Act # (1) which is an "Activity Number" into cell A5 and a Date (1/26/18) into B5 I want it to lookup the corresponding data in the Safety Activity "Legend" at the bottom and display the Act % "Activity %" in Employee 1's B25 which would be .4.

    Should give Safety Activities Act #.... =VLOOKUP(A5,A30:B36,1,0)
    Should gives Safety Activities Act %.... =VLOOKUP(A5,$A$30:$AB$36,28,0)

    The problem I have is there is a limit "Activity Limit" to the times a Act # can be performed. So using the example above I used Act # 1 and its Activity Limit is 2 so if an employee enters it twice lets say A5 on 1/26/18 and A6 on 1/27/18 they reached their limit so how do I make it not be able to add an .4 in if someone enters another Act 1 lets say on A7 1/28/18 I want them to get zero percent for that because they reached their limit.
    Attached Files Attached Files
    Last edited by oxicottin; 01-26-2018 at 06:54 AM.

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    I'd make a user defined function since IMHO the logic is too complicated for just worksheet formulas

    IF I UNDERSTAND your logic ...


    Option Explicit
    
    Function ActivityPercent(actNumbers As Range, ActLimits As Range) As Double
        Dim i As Long
        Dim actNumber As Variant, limitNumber As Variant, limitMax As Variant, limitPercent As Variant
        Dim actCount() As Long
        Dim actTotal As Double
        
        Application.Volatile
        
        'move data into arrays
        With Application.WorksheetFunction
            actNumber = .Transpose(actNumbers.Columns(1))
            limitNumber = .Transpose(ActLimits.Columns(1))
            limitMax = .Transpose(ActLimits.Columns(2))
            limitPercent = .Transpose(ActLimits.Columns(28))
        End With
    
    
        'create and init a max count array
        ReDim actCount(LBound(limitNumber) To UBound(limitNumber))
        For i = LBound(limitMax) To UBound(limitMax)
            actCount(i) = limitMax(i)
        Next I
    
        'see if activity count exceeded by decrementing max
        For i = LBound(actNumber) To UBound(actNumber)
            If actNumber(i) > 0 Then
                If limitMax(actNumber(i)) > 0 Then
                    limitMax(actNumber(i)) = limitMax(actNumber(i)) - 1
                    actTotal = actTotal + limitPercent(actNumber(i))
                End If
            End If
        Next I
    
        ActivityPercent = actTotal
    
    End Function
    Attached Files Attached Files
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    Spot on... Thank you!

Posting Permissions

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