+ Reply to Thread
Results 1 to 4 of 4

Thread: Selecting test results of specific person

  1. #1
    Registered User
    Join Date
    06-06-2009
    Location
    Helmond
    MS-Off Ver
    Excel 2007
    Posts
    18

    Selecting test results of specific person

    Hello everybody,

    I'll try to explain my problem: I have a list of 'patients' ('patientenlijst' in workbook) that have done some tests. The results of the tests of all patients are stored on another worksheet ('Gegevens2' in workbook). There the tests are sorted by testdate (not patientname). Now I have another worksheet ('testoverzicht' in workbook) where I am able to select the name of a patient... my problem is that I want all the testresults of that specific person to be displayed on the same sheet (sorted by date too)...

    If anyone has any idea as to how I could go about this I would be VERY thankfull...

    I have attached my excel file as a reference...
    Attached Files Attached Files
    Last edited by speedone; 09-30-2010 at 12:20 PM.

  2. #2
    Valued Forum Contributor
    Join Date
    07-07-2005
    Location
    England
    MS-Off Ver
    2003 Pro
    Posts
    338

    Re: Selecting test results of specific person

    Try this..

    Stick a button on the 'testoverzicht' sheet and run this code

    Sub CollectPatientResults()
    'Turn off screen updates
    Application.ScreenUpdating = False
    'Delete any previous data
    Sheets("testoverzicht").Range("F2:AK500").ClearContents
    'Store patient name
    Patient = Sheets("testoverzicht").Range("C3").Value
    'Activate Gevens2 sheet
    Sheets("Gegevens2").Select
    'Move to last row on sheet so we know how many rows to loop through
    Range("A1").Select
    Selection.End(xlDown).Select
    LastRow = ActiveCell.Row
    'Loop from row 2 to last row with data in
    For x = 2 To LastRow
    'Check if patient appears on this row
    If Cells(x, 2).Value = Patient Then
    'Copy Data starting from TestDatum column (E) to opmerkingen (AJ) of current row
    Cells(x, 5).Resize(Selection.Rows.Count, Selection.Columns.Count + 31).Copy
    'Paste Data into testoverzicht sheet
    Sheets("testoverzicht").Select
    'Go to bottom of sheet then up to next used row (So we can past data below last used row
    Range("F65536").Select
    Selection.End(xlUp).Select
    'Paste Data
    ActiveCell.Offset(1, 0).Select
    Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats
    Application.CutCopyMode = False 'this clears the original copy from the clipboard
    'Back to original sheet...
    Sheets("Gegevens2").Select
    End If
    Next
    'Back to testoverzicht sheet...
    Sheets("testoverzicht").Select
    'Turn back ON screen updates
    Application.ScreenUpdating = True
    End Sub

  3. #3
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    3,788

    Re: Selecting test results of specific person

    See if this works as you want.
    Sub x()
    
    Dim rData As Range
    
    Application.ScreenUpdating = False
    
    With Sheets("Gegevens2")
        .AutoFilterMode = False
        .Range("A1").AutoFilter Field:=2, Criteria1:=Sheets("testoverzicht").Range("C3")
        With .AutoFilter.Range
            On Error Resume Next
            Set rData = .Offset(1, 4).Resize(.Rows.Count - 1, .Columns.Count - 4).SpecialCells(xlCellTypeVisible)
            On Error GoTo 0
            If Not rData Is Nothing Then
                With Sheets("testoverzicht")
                    If Len(.Range("F2")) > 0 Then
                        .Range("F2", .Range("F2").End(xlDown)).Resize(, 32).ClearContents
                    End If
                    rData.Copy
                    .Range("F2").PasteSpecial xlValues
                End With
            End If
        End With
        .AutoFilterMode = False
    End With
    
    Application.ScreenUpdating = True
    
    End Sub

  4. #4
    Registered User
    Join Date
    06-06-2009
    Location
    Helmond
    MS-Off Ver
    Excel 2007
    Posts
    18

    Re: Selecting test results of specific person

    StephenR,

    I tried your method and it works like a charm!

    Johncassel also thanks for your input. I will save the code in case I run in to some kind of problem...

    I also changed the code to a Worksheet_Change so it updates as soon as I select another person from the dropdown list...

    Thanks again people, you saved my day! :-)

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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.2.0