How to count names repeated in consecutive rows as "1"

halesowenmum

Active Member
Joined
Oct 20, 2010
Messages
383
Office Version
  1. 365
Platform
  1. Windows
Hi there

Can anyone assist with this?

I've got a spreadsheet with rows of patient names in it. In some cases it's one name per row and in others there may be more than one row with the same name in it. Each row signifies a clinical review having been conducted for that patient. It's one review max conducted per day. Where the patient was in for say three days there name would appear the same in three separate rows but always one above the other whilst the dates in the date column would be different to show the three different days they were reviewed on.

I need to count up the ones where the same name appears multiple times so that if there were three rows it would mean the patient had received three clinical reviews over three different consecutive days - BUT it would still only count as one patient). It's that count of patients that I need.

The above doesn't account for the following though and I'm not sure if we can cover this off somehow:

Patients may finish their visit and be discharged. But they might return to hospital a week or a month later if they get ill again. That would count effectively as 'another' patient (even though it's the same one). Is there any way to capture them as well??

My columns references are:

E - first name
F - last name
AE - date

Many thanks.
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
This is a Double Click Event based on a selection in column "E"
If the patient has had 2 appointments of 3 continuous days then later on 4 continuous days then the results in a msgbox will show
The patients name and = 3,4.
If you want to show all the patients results in sheet or single results please state where you would like to see them.
Code:
Private [COLOR="Navy"]Sub[/COLOR] Worksheet_BeforeDoubleClick(ByVal Target [COLOR="Navy"]As[/COLOR] Range, Cancel [COLOR="Navy"]As[/COLOR] Boolean)
[COLOR="Navy"]Dim[/COLOR] Rng [COLOR="Navy"]As[/COLOR] Range, Dn [COLOR="Navy"]As[/COLOR] Range, n [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] nRng [COLOR="Navy"]As[/COLOR] Range, Txt [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]String,[/COLOR] R [COLOR="Navy"]As[/COLOR] Range, nStr [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]String[/COLOR]
[COLOR="Navy"]Set[/COLOR] Rng = Range(Range("E2"), Range("E" & Rows.Count).End(xlUp))
    [COLOR="Navy"]If[/COLOR] Not Intersect(Target, Rng) [COLOR="Navy"]Is[/COLOR] Nothing [COLOR="Navy"]Then[/COLOR]
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng
    Txt = Dn.Value & " " & Dn.Offset(, 1).Value
      [COLOR="Navy"]If[/COLOR] Target.Value & " " & Target.Offset(, 1).Value = Txt [COLOR="Navy"]Then[/COLOR]
        [COLOR="Navy"]If[/COLOR] nRng [COLOR="Navy"]Is[/COLOR] Nothing [COLOR="Navy"]Then[/COLOR] [COLOR="Navy"]Set[/COLOR] nRng = Dn Else [COLOR="Navy"]Set[/COLOR] nRng = Union(nRng, Dn)
       [COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR] Dn
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] R [COLOR="Navy"]In[/COLOR] nRng.Areas
    nStr = nStr & IIf(nStr = "", R.Count, "," & R.Count)
[COLOR="Navy"]Next[/COLOR] R
    MsgBox Txt & " = " & nStr
    [COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0
Oooh, I am sorry I don't understand (sorry!!). Is this VBL - I've no idea how I'd enter that and make it work?
 
Upvote 0
Are you looking for something like below, probably the total patient see ions ?
Excel Workbook
EFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAGAH
1FirstLast************************Date***
2TomJones************************01/01/2016*Total reviews11
3TomJones************************02/01/2016*Total Patients6
4TomJones************************03/01/2016*Total Patient Sessions8
5FredFlintstone************************04/01/2016***
6CarolKing************************05/01/2016***
7CarolKing************************06/01/2016***
8TomThumb************************07/01/2016***
9BillJones************************08/01/2016***
10TomJones************************09/01/2016***
11SidStrange************************10/01/2016***
12TomThumb************************11/01/2016***
Sheet1


NB the last two formulas are array formulas so confirm with Ctrl + Shift + Enter and excel will add the curly braces.
 
Upvote 0
Yes absolutely that's how it looks you clever sausage. That is so clever!

I'll have a look at trying to do this tomorrow on me old spreadsheet and see if I can input that all correctly.

Thank you and I'll feed back as to how I get on.
 
Upvote 0
Okey dokey so I've inserted the formulas and the first one worked a treat.

But when I put the other two in they just sit there as text.

I tried Ctrl Ving and Ctrl+Shift-Entering with and without {} but to no avail. Cells are currently set to general so I then tried having set it to number - no dice.
 
Upvote 0
Also, sorry, shouldn't Total Pts be 7?

Thumb has to count as 2 patients because he's come in gone home then come in again??
 
Upvote 0
Okey dokey so I've inserted the formulas and the first one worked a treat.

But when I put the other two in they just sit there as text.

I tried Ctrl Ving and Ctrl+Shift-Entering with and without {} but to no avail. Cells are currently set to general so I then tried having set it to number - no dice.


Formulas must start with '=' . You are likely copying the whole of the above, including the curly braces and posting it into cell. The '{' will then make that as text. If so then REMOVE the curly braces from each end of the text and then do Ctrl + Shift + Enter and the braces will be entered automatically.

As for the Total Patients... apologies but please totally disregard that formula with I should not have posted. (Silly sausage) You will see it refers to column A and was just something I played with when working out your Total Sessions formula.
There are 6 unique patient names and two patients have each had two sessions so 8 sessions.

Hope that sorts it
 
Upvote 0
I have absolutely definitely copied the formula without the curlies and with the = sign and pasted in both possible ways but it still just displays it at text (doesn't add the curly braces) .... or it just doesn't do anything. Could it be any of my Excel settings???

Thanks for the explanation re the patient numbers!
 
Upvote 0
Then it sounds like the cell you are trying to enter the formula into is set to TEXT format?
Select the empty cell and make sure format is set to GENERAL then enter the formula.
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,694
Members
448,979
Latest member
DET4492

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