+ Reply to Thread
Results 1 to 5 of 5

Calculating Last Vote

Hybrid View

willhh3 Calculating Last Vote 11-10-2015, 11:11 AM
stnkynts Re: Calculating Last Vote 11-10-2015, 12:59 PM
rcm Re: Calculating Last Vote 11-10-2015, 02:09 PM
willhh3 Re: Calculating Last Vote 11-13-2015, 04:00 PM
rcm Re: Calculating Last Vote 11-13-2015, 04:05 PM
  1. #1
    Registered User
    Join Date
    11-09-2015
    Location
    Florida
    MS-Off Ver
    O365
    Posts
    61

    Calculating Last Vote

    Hello!

    I need some help with the sample file. I'm trying to calculate the most recent vote that 1 of 4 people made, and apply a set status. I've include the below conditions in the sample file and what I think the output should look like (Sample_Conditions tab). The Votes and Voter List tabs will be what is in the weekly workbook. Any help would be appreciated.

    Conditions:
    All four people on the Voter List tab, must vote prior to the Deadline indicated.
    They each can vote multiple times on one order number, but we are only concerned with the last vote.
    Voters may not vote at all.
    There is a varying number of rows week to week, depending on how many order numbers there are for the week.

    Trim list down to last vote for each person that is listed on the Voter List tab.

    If last vote equals "Approve" or "Defer" and is before the deadline then Status equals "Met"
    If last vote equals "Approve" or "Defer" and is after the deadline, then Status equals "Missed"

    If the a person in the Voter List doesn't have a row associated with an Order number, they didn't vote.
    If this condition is met, add a row with the Order Number and the Voter Name. Date/Time is blank and Status equals "No Vote"

    Thank you in advance for any assistance.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Calculating Last Vote

    That was quite a bit. Create a new sheet named "Output" for the output result:

    Sub Create_Summary()
    Dim dOrders As Object:  Set dOrders = CreateObject("Scripting.Dictionary")
    Dim ws1 As Worksheet:   Set ws1 = Sheets("Sample_Conditions")
    Dim ws3 As Worksheet:   Set ws3 = Sheets("Voter List")
    Dim ws4 As Worksheet:   Set ws4 = Sheets("Output") 'a new sheet that you need to create.  Feel free to change the sheet name here
    Dim arrVoters As Variant, k As Variant, arrOrders As Variant
    Dim i As Long, ii As Long
    Dim rVoter As Range
    
    Application.ScreenUpdating = False
    
    If Not Evaluate("=ISREF('" & ws4.Name & "'!A1)") Then
        MsgBox ("You didn't make an output sheet")
        Exit Sub
    Else
        ws1.Range("A1").EntireRow.Copy ws4.Range("A1")
    End If
    
    arrVoters = ws3.Range("A2:A" & ws3.Range("A" & Rows.Count).End(xlUp).Row)
    arrOrders = ws1.Range("A2:A" & ws1.Range("A" & Rows.Count).End(xlUp).Row)
    
    For i = LBound(arrOrders, 1) To UBound(arrOrders, 1)
        dOrders(arrOrders(i, 1)) = 1
    Next i
    
    For Each k In dOrders.keys
        With ws1
            .AutoFilterMode = False
            .Range("A1:A" & ws1.Range("A" & Rows.Count).End(xlUp).Row).AutoFilter 1, k
            For ii = LBound(arrVoters, 1) To UBound(arrVoters, 1)
                Set rVoter = .Range("C1:C" & ws1.Range("C" & Rows.Count).End(xlUp).Row).SpecialCells(xlCellTypeVisible).Find(arrVoters(ii, 1), , xlValues, xlWhole, , xlPrevious)
                If Not rVoter Is Nothing Then
                    If .Range("E" & rVoter.Row).Value > .Range("B" & rVoter.Row).Value Then 'met
                        rVoter.EntireRow.Copy ws4.Range("A" & Rows.Count).End(3)(2)
                        ws4.Range("F" & Rows.Count).End(3)(2).Value = "Met"
                    Else 'missed
                        rVoter.EntireRow.Copy ws4.Range("A" & Rows.Count).End(3)(2)
                        ws4.Range("F" & Rows.Count).End(3)(2).Value = "Missed"
                    End If
                Else 'no vote
                    .Range("C2:C" & ws1.Range("C" & Rows.Count).End(xlUp).Row).SpecialCells(xlCellTypeVisible).Cells(1, 1).EntireRow.Copy ws4.Range("A" & Rows.Count).End(3)(2)
                    ws4.Range("B" & ws4.Range("A" & Rows.Count).End(xlUp).Row, "D" & ws4.Range("A" & Rows.Count).End(xlUp).Row).ClearContents
                    ws4.Range("C" & Rows.Count).End(3)(2).Value = arrVoters(ii, 1)
                    ws4.Range("F" & Rows.Count).End(3)(2).Value = "No Vote"
                End If
            Next ii
            .ListObjects("Table1").Range.AutoFilter Field:=1
        End With
    Next k
    
    Application.ScreenUpdating = True
        
    End Sub
    If you are happy with my response please click the * in the lower left of my post.

  3. #3
    Forum Expert
    Join Date
    11-28-2012
    Location
    Guatemala
    MS-Off Ver
    Excel 2010
    Posts
    2,394

    Re: Calculating Last Vote

    try this by running the macro
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    11-09-2015
    Location
    Florida
    MS-Off Ver
    O365
    Posts
    61

    Re: Calculating Last Vote

    Looks like both of these solutions work great! Thank you both...I know this was a tricky one!

  5. #5
    Forum Expert
    Join Date
    11-28-2012
    Location
    Guatemala
    MS-Off Ver
    Excel 2010
    Posts
    2,394

    Re: Calculating Last Vote

    you´re welcome, it was a quite a challange but happy to know that it help you out!!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Vote Tabulation Format
    By rkmcdaniel in forum Excel General
    Replies: 1
    Last Post: 06-23-2014, 04:52 PM
  2. Vote - To opt out Voter after voted and duplicate vote count cross dept vote
    By Dahlia in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-15-2014, 09:41 PM
  3. 'Rate this thread' - What happens to the vote?
    By Ace_XL in forum The Water Cooler
    Replies: 3
    Last Post: 11-26-2013, 04:05 AM
  4. VBA REQUEST or VOTE ????
    By downtown1933 in forum The Water Cooler
    Replies: 3
    Last Post: 03-09-2013, 12:45 PM
  5. VBA REQUEST or VOTE ????
    By downtown1933 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-09-2013, 12:33 PM
  6. Car Show Vote Counting Help
    By MikeInPalouse in forum Excel General
    Replies: 8
    Last Post: 09-14-2009, 03:16 PM

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