VBA help: Removing Patient from list that has Discharged, and for non-discharged getting the time period

amyap

New Member
Joined
Apr 26, 2024
Messages
1
Office Version
  1. 365
Platform
  1. Windows
Hi all,

I'm trying to write something that would help make my work easier.

1) Trying to remove the row of patient that have discharged.
2) Getting the date time start and end in that ward.

Is it possible? I'm really new to VBA and i'm not sure how to tackle this.

Thanks so much

Here's how it looks like:
S/NID.NameCase RelationshipMovement Start DateMovement Start TimeMovement End DateMovement End TimeWardBed
1​
P0001Alan AInpatient05.04.2024
16:32:40​
06.04.2024
2:42:47​
2​
P0001Alan AInpatient06.04.2024
2:42:47​
08.04.2024
14:36:08​
W10W1002
3​
P0001Alan AInpatient08.04.2024
14:36:08​
31.12.9999
24:00:00​
W10W1002
4​
P0002Brian BInpatient09.04.2024
12:30:02​
09.04.2024
14:23:48​
5​
P0002Brian BInpatient09.04.2024
12:53:00​
09.04.2024
12:53:00​
6​
P0002Brian BInpatient09.04.2024
14:23:48​
10.04.2024
21:05:00​
W20W2001
7​
P0002Brian BInpatient10.04.2024
21:05:00​
12.04.2024
20:29:05​
W20W2001
8​
P0002Brian BInpatient12.04.2024
20:29:05​
23.04.2024
15:19:15​
W10W1003
9​
P0002Brian BDischarged23.04.2024
15:19:15​
23.04.2024
15:19:15​
W10W1003
10​
P0003Charles CInpatient22.04.2024
16:20:58​
22.04.2024
17:12:52​
11​
P0003Charles CInpatient22.04.2024
17:12:52​
23.04.2024
9:31:47​
W30W3006
12​
P0003Charles CInpatient23.04.2024
9:31:47​
23.04.2024
16:29:16​
W30W3006
13​
P0003Charles CInpatient23.04.2024
16:29:16​
31.12.9999
24:00:00​
W10W1003
14​
P0004Dave DInpatient30.03.2024
17:22:56​
30.03.2024
20:12:07​
15​
P0004Dave DInpatient30.03.2024
20:12:07​
01.04.2024
20:42:01​
W30W3008
16​
P0004Dave DInpatient01.04.2024
20:42:01​
03.04.2024
21:25:56​
W40W4001
17​
P0004Dave DInpatient03.04.2024
21:25:56​
05.04.2024
16:07:31​
W10W1001
18​
P0004Dave DInpatient05.04.2024
16:07:31​
11.04.2024
21:30:54​
W10W1001
19​
P0004Dave DInpatient11.04.2024
21:30:54​
31.12.9999
24:00:00​
W10W1001
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Hi all,

I'm trying to write something that would help make my work easier.

1) Trying to remove the row of patient that have discharged.
2) Getting the date time start and end in that ward.

Is it possible? I'm really new to VBA and i'm not sure how to tackle this.

Thanks so much

Here's how it looks like:
S/NID.NameCase RelationshipMovement Start DateMovement Start TimeMovement End DateMovement End TimeWardBed
1​
P0001Alan AInpatient05.04.2024
16:32:40​
06.04.2024
2:42:47​
2​
P0001Alan AInpatient06.04.2024
2:42:47​
08.04.2024
14:36:08​
W10W1002
3​
P0001Alan AInpatient08.04.2024
14:36:08​
31.12.9999
24:00:00​
W10W1002
4​
P0002Brian BInpatient09.04.2024
12:30:02​
09.04.2024
14:23:48​
5​
P0002Brian BInpatient09.04.2024
12:53:00​
09.04.2024
12:53:00​
6​
P0002Brian BInpatient09.04.2024
14:23:48​
10.04.2024
21:05:00​
W20W2001
7​
P0002Brian BInpatient10.04.2024
21:05:00​
12.04.2024
20:29:05​
W20W2001
8​
P0002Brian BInpatient12.04.2024
20:29:05​
23.04.2024
15:19:15​
W10W1003
9​
P0002Brian BDischarged23.04.2024
15:19:15​
23.04.2024
15:19:15​
W10W1003
10​
P0003Charles CInpatient22.04.2024
16:20:58​
22.04.2024
17:12:52​
11​
P0003Charles CInpatient22.04.2024
17:12:52​
23.04.2024
9:31:47​
W30W3006
12​
P0003Charles CInpatient23.04.2024
9:31:47​
23.04.2024
16:29:16​
W30W3006
13​
P0003Charles CInpatient23.04.2024
16:29:16​
31.12.9999
24:00:00​
W10W1003
14​
P0004Dave DInpatient30.03.2024
17:22:56​
30.03.2024
20:12:07​
15​
P0004Dave DInpatient30.03.2024
20:12:07​
01.04.2024
20:42:01​
W30W3008
16​
P0004Dave DInpatient01.04.2024
20:42:01​
03.04.2024
21:25:56​
W40W4001
17​
P0004Dave DInpatient03.04.2024
21:25:56​
05.04.2024
16:07:31​
W10W1001
18​
P0004Dave DInpatient05.04.2024
16:07:31​
11.04.2024
21:30:54​
W10W1001
19​
P0004Dave DInpatient11.04.2024
21:30:54​
31.12.9999
24:00:00​
W10W1001
this sub to delete "Discharged" patient:
VBA Code:
Sub test()
    Dim cll As Range, rng As Range
    Set rng = ActiveSheet.Range("D2:D" & ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row)
    For Each cll In rng
        If cll.Text = "Discharged" Then cll.EntireRow.Delete (xlUp)
    Next cll
End Sub
about "Getting the date time start and end in that ward.", i don't understand it, please explain
 
Upvote 0

Forum statistics

Threads
1,215,491
Messages
6,125,098
Members
449,205
Latest member
ralemanygarcia

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