+ Reply to Thread
Results 1 to 11 of 11

Getting all the information to be shown during the search

Hybrid View

  1. #1
    Registered User
    Join Date
    07-18-2020
    Location
    Saudi Arabia
    MS-Off Ver
    2019
    Posts
    10

    Getting all the information to be shown during the search

    Hi
    I have a file where you can find 2 sheets ( Data and Interface ) The datasheet the user must enter the data in the sheet. In the other sheet (Interface) I applied Advance Filter to make the search easier for the user to find the required information (Detect the patients returned to the Emergency Department within 72 hours). Is there a method to make the user search for the information and to get all the visits for the patient and which the visit within 72 hours?
    Attached Files Attached Files
    Last edited by Dana2020; 01-25-2021 at 06:38 AM.

  2. #2
    Forum Expert nankw83's Avatar
    Join Date
    08-31-2015
    Location
    Kuwait
    MS-Off Ver
    365
    Posts
    1,713

    Re: Getting all the information to be shown during the search

    Hi Dana,

    Try below code, for calculating the 72 hours the code uses your current time Now() and the date/time of Date of ER Visit & Registration Time

    Sub Test()
    
    Dim Lc As Long, Lr As Long, Rg As Range
    Set Rg = Sheet2.[A1:A2]
    Rg = [{"Flag";1}]
    
    With Sheet1
       Lc = .Cells(1, Columns.Count).End(1).Column + 1
       Lr = .Cells(Rows.Count, 1).End(3).Row
       .Cells(1, Lc).Resize(Lr) = Evaluate("if(now()-3<" & .[B1].Resize(Lr).Address(, , , True) _
             & "+" & .[C1].Resize(Lr).Address(, , , True) & ",1,"""")")
       .Cells(1, Lc) = "Flag"
       .[A1].CurrentRegion.AdvancedFilter 2, Rg, Sheet2.[F11:H11]
       .Cells(1, Lc).Resize(Lr).ClearContents
    End With
    
    Rg.ClearContents
    
    End Sub
    If I was able to help, you can thank me by clicking the * Add Reputation under my user name

  3. #3
    Registered User
    Join Date
    07-18-2020
    Location
    Saudi Arabia
    MS-Off Ver
    2019
    Posts
    10

    Re: Getting all the information to be shown during the search

    I need to show all the records of the patients who returned to ER within 72 hours and also their previous visits. When I make a filter to the patients who returned to ER, what I get is only one record for each patient without their previous visits

  4. #4
    Forum Expert nankw83's Avatar
    Join Date
    08-31-2015
    Location
    Kuwait
    MS-Off Ver
    365
    Posts
    1,713

    Re: Getting all the information to be shown during the search

    Try below code ...
    Sub Test()
    
    Dim Lc As Long, Lr As Long, Rg As Range, j$
    Set Rg = Sheet2.[A1:A2]
    Rg = [{"Flag";1}]
    
    With Sheet1
       Lc = .Cells(1, Columns.Count).End(1).Column + 1
       Lr = .Cells(Rows.Count, 1).End(3).Row
       .Cells(1, Lc).Resize(Lr) = Evaluate("if(now()-3<" & .[B1].Resize(Lr).Address(, , , True) _
             & "+" & .[C1].Resize(Lr).Address(, , , True) & ",1,"""")")
       j = Split(.Cells(1, Columns.Count).End(1).Address, "$")(1)
       .Cells(1, Lc + 1).Resize(Lr).Formula = "=SUMIF(A:A,A1," & j & ":" & j & ")"
       .Cells(1, Lc + 1) = "Flag"
       .[A1].CurrentRegion.AdvancedFilter 2, Rg, Sheet2.[F11:H11]
       .Cells(1, Lc).Resize(Lr, 2).ClearContents
    End With
    
    Rg.ClearContents
    
    End Sub

  5. #5
    Registered User
    Join Date
    07-18-2020
    Location
    Saudi Arabia
    MS-Off Ver
    2019
    Posts
    10

    Re: Getting all the information to be shown during the search

    The code doesn't work

  6. #6
    Forum Expert nankw83's Avatar
    Join Date
    08-31-2015
    Location
    Kuwait
    MS-Off Ver
    365
    Posts
    1,713

    Re: Getting all the information to be shown during the search

    What happens when you run the code ? Does it give any error ? If you're trying in the sample file you posted in post #1, you need to change some of the dates as all of them are more than 72 hours

  7. #7
    Registered User
    Join Date
    07-18-2020
    Location
    Saudi Arabia
    MS-Off Ver
    2019
    Posts
    10

    Re: Getting all the information to be shown during the search

    When I run the code, the results are not what I want.
    I don,t need to change any dates
    There is a formula already in Column( O ), it will show if the patient returned within 72 hours
    What I want is to show all the records for the patients who returned within 72 hours plus their previous visits, Because when I make a filter for the patients returned, it will show only one record for each patient
    Attached Files Attached Files
    Last edited by Dana2020; 01-31-2021 at 05:26 AM.

  8. #8
    Forum Expert nankw83's Avatar
    Join Date
    08-31-2015
    Location
    Kuwait
    MS-Off Ver
    365
    Posts
    1,713

    Re: Getting all the information to be shown during the search

    Quote Originally Posted by Dana2020 View Post
    There is a formula already in Column( O ), it will show if the patient returned within 72 hours
    This wasn't clear to me ... Try below code

    Sub Test()
    
    Dim Lc As Long, Lr As Long, Rg As Range, j$
    Set Rg = Sheet2.[A1:A2]
    Rg = [{"Flag";">0"}]
    
    With Sheet1
       Lc = .Cells(1, Columns.Count).End(1).Column + 1
       Lr = .Cells(Rows.Count, 1).End(3).Row
       j = Split(.Cells(1, Columns.Count).End(1).Address, "$")(1)
       .Cells(1, Lc).Resize(Lr).Formula = "=IF(ROW()=1,""Flag"",COUNTIFS(A:A,A1," & j & ":" & j & ",""Yes""))"
       .[A1].CurrentRegion.AdvancedFilter 2, Rg, Sheet2.[F11:H11]
       .Cells(1, Lc).Resize(Lr).ClearContents
    End With
    
    Rg.ClearContents
    
    End Sub

  9. #9
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,643

    Re: Getting all the information to be shown during the search

    Dana2020,

    Try
    Sub Search()
        Dim r As Range
        Sheets("interface").[f11].CurrentRegion.Offset(1).Clear
        With Sheets("data")
            .[aa2].Formula = "=and(b2>='interface'!$c$5,b2<='interface'!$d$5,o2=""Yes"")"
            .Cells(1).CurrentRegion.AdvancedFilter 2, .[aa1:aa2], Sheets("interface").[f11].CurrentRegion
            .[aa2].Clear
        End With
    End Sub

  10. #10
    Registered User
    Join Date
    07-18-2020
    Location
    Saudi Arabia
    MS-Off Ver
    2019
    Posts
    10

    Re: Getting all the information to be shown during the search

    These codes do not give me the results I want

  11. #11
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,643

    Re: Getting all the information to be shown during the search

    Bad luck. .

+ 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. Replies: 7
    Last Post: 07-03-2020, 07:14 AM
  2. Replies: 1
    Last Post: 12-24-2019, 12:23 PM
  3. Replies: 0
    Last Post: 02-07-2016, 07:47 AM
  4. Column of Text Shown = Total Times Shown?
    By philcassell in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 07-19-2006, 02:25 AM
  5. [SOLVED] Named Ranges shown (or not shown) as blue means what?
    By wdeleo in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 06:05 AM
  6. Named Ranges shown (or not shown) as blue means what?
    By wdeleo in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 02:05 AM
  7. [SOLVED] Named Ranges shown (or not shown) as blue means what?
    By wdeleo in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-05-2005, 11:05 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