How to count name appearence but only once per given dates

Miro H

New Member
Joined
Mar 25, 2015
Messages
15
Office Version
  1. 365
Platform
  1. Windows
Hi all,

This is my first post, hope someone can help me.

I have inherited an excel sheet that tracks the activities on site, by date and personnel. It looks something like this.

DateSitePerson
21/4/20151A, B, C
21/4/20152D, E
22/4/20152A, B, C
22/4/20153D, E, F
22/4/20154A, C, F
22/4/20155B, E, F
23/4/20155A, B
23/4/20156A

<tbody>
</tbody>


I have to do the report how many days each person spend on sites (out of office).

Based on the table above this would be the result:

PersonDays
A3
B3
C2
D2
E2
F1

<tbody>
</tbody>


I've tried with COUNTIF, but simple COUNTIF function would not help as I need to count each person only once per given date. For example person A appears 5 times in total, but only on 3 different days. Or Person F appears 3 times, but only on 1 day so it was 1 day out of office.
So I'm stuck now.

One more thing, I can't change the appearance of original excel sheet.


Could anyone suggest how to make a formula that would automatically count this?
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Assuming that all the sites you list are "offsite" sites, the site is not relevant only the first and third columns are relevant to what you want to calculate. Here's a UDF that you can use to do that. It's used just like any worksheet function as in the example below (copy formula in G2 down to cover all persons).
Excel Workbook
ABCDEFG
1DateSitePersonPersonDays Offsite
221/4/20151A, B, CA3
321/4/20152D, EB3
422/4/20152A, B, CC2
522/4/20153D, E, FD2
622/4/20154A, C, FE2
722/4/20155B, E, FF1
823/4/20155A, B
923/4/20156A
Sheet6


To install the code:
1. With your workbook active press Alt and F11 keys. This will open the VBE window.
2. In the project tree on the left of the VBE window, find your project and click on it.
3. On the VBE menu: Insert>Module
4. Copy the code from your browser window and paste it into the white space in the VBE window.
5. Close the VBE window and Save the workbook. If you are using Excel 2007 or a later version do a SaveAs and save it as a macro-enabled workbook (.xlsm file extension).
6. Press Alt+F8 keys to run the code
Code:
Function DaysOffSite(S As String, Dtes As Range) As Variant
Dim d As Object, Ct As Long, c As Range, i As Long
Set d = CreateObject("Scripting.dictionary")
For Each c In Dtes
    If InStr(c.Offset(0, 2).Value, S) > 0 Then
        If Not d.exists(c.Value) Then
            Ct = Ct + 1
            d.Add c.Value, Ct
        End If
    End If
Next c
DaysOffSite = Ct
End Function
 
Upvote 0
Are the dates true date values? If so, try...

A1:F9

DateSitePersonPersonDays
4/21/151A, B, CA3
4/21/152D, EB3
4/22/152A, B, CC2
4/22/153D, E, FD2
4/22/154A, C, FE2
4/22/155B, E, FF1
4/23/155A, B
4/23/156A

<tbody>
</tbody>

F2, confirmed with CONTROL+SHIFT+ENTER, and copied down:

=SUM(IF(FREQUENCY(IF(ISNUMBER(SEARCH(", "&E2&",",", "&$C$2:$C$9&",")),IF(ISNUMBER($A$2:$A$9),$A$2:$A$9)),$A$2:$A$9)>0,1))

Hope this helps!
 
Upvote 0
Nice Domenic. I was trying to figure out a formula solution to this but couldn't quite get there. I was using Transpose and countif, but I couldn't figure it out. Frequency is still one that I need to look into more. Cool solution.
 
Upvote 0
Nice Domenic. I was trying to figure out a formula solution to this but couldn't quite get there. I was using Transpose and countif, but I couldn't figure it out. Frequency is still one that I need to look into more. Cool solution.

Thanks! Much appreciated!

Cheers!
 
Upvote 0

Forum statistics

Threads
1,214,821
Messages
6,121,759
Members
449,048
Latest member
excelknuckles

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top