Question:
Excel: how to manage Lookup data in one row?
CrazyCrab
2014-01-22 15:16:21 UTC
Hi all,

I have a really simple table:

On the first column i have the date (1/1; 1/2, 1/3, 1/4 etc) and in the row i have patients coming in that day (could be 10-30 entries per date). Therefore, the column reference is not fixed, and a certain patient could be reported in column 5 one time and 10 on another date.

My goal would be to have a formula where i select a name and ALL dates when he came in pop up.

Can you help me with this?
thanks!!
Five answers:
garbo7441
2014-01-22 20:32:30 UTC
Your question shows patients only using first names. If you wish to extract all visits for a patient named 'Mark' and there are three different patients named 'Mark', your data extract will be flawed.



In any event here is a method to simply double click any cell and enter the patient name. A message box will then display containing all visits for that patient, regardless of column/row.



Copy the following event handler to the clipboard (highlight the entire code, right click inside the highlighted area, and 'Copy'):



Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, _

Cancel As Boolean)

selPatient = UCase(InputBox("Enter Patient Name", "Search For"))

If selPatient = "" Then

Exit Sub

End If

On Error Resume Next

For Each cell In ActiveSheet.UsedRange

If UCase(cell) = selPatient Then

pVisits = pVisits & Format(Cells(cell.Row, 1).Value, "m/d") & ", "

ctr = ctr + 1

End If

Next

pVisits = Left(pVisits, Len(pVisits) - 3)

If ctr = 0 Then

MsgBox Application.Proper(selPatient) & " not found", _

vbInformation, "No Record"

Target.Offset(1).Select

Exit Sub

End If

MsgBox Application.Proper(selPatient) & Chr(10) & Chr(10) & _

pVisits, vbOKOnly, "Visits"

Target.Offset(1).Select

End Sub



Select the worksheet containing the patient visits to evaluate and right click the sheet tab at the bottom.



Select 'View Code'.



Paste the event handler into the white editing area to the right (right click inside the area and 'Paste').



Close the VBE (red button - top right).



Double click any cell and enter the patient name. The results will be displayed. If there are no visits for the patient name entered, the message box will so state.



Note: the event handler is not case sensitive. If the patient name is John Smith, you can enter the enter the name as: JOHN SMITH, john smith, John Smith, and even JoHn SMiTh.
Nahum
2014-01-22 23:16:03 UTC
Rather than having one row per day, it may be better to have one row per patient for each day:



1/1 Jonh

1/1 Phil

1/1 MArk

1/2 MArk

1/2 Phil

1/2 John

â‹®



This way, you don't have to split up the name entries since there is only one in each row. Excel has an easier time with this sort of arrangement—functions like COUNTIF and FREQUENCY, and features like sorting and filtering will become usable.



You can conditionally format the rows by using ISODD or ISEVEN on the date as the condition, or perhaps assign different colors for each day of the week by using the WEEKDAY function.
APN
2014-01-24 01:34:03 UTC
Use DATA --> FILTER --> AdvancedFilters



The area on the left is the data and on the right is the criterion. In my example I have 4 slots and you will have 30 slots. In the cells of the criterion fill it up with the same name repeated in separate rows.



The menu will ask for



Date Slot1 Slot2 Slot3 Slot4 Slot1 Slot2 Slot3 Slot4

01-Jan AA BB AA

02-Jan CC DD EE FF AA

03-Jan BB FF AA AA

AA



Use the option to copy the selected rows to a different set of cells. Only the dates on which that patient came in appear.



OK
buz
2014-01-22 17:14:46 UTC
I have an idea that might work - if you had a blank row (say Row 1) above your table, and a column (Col B) between the date column (Col A) and the columns where you entered the names (Col C to Col Z)



Then if you entered the name you wanted to check in cell B1 and had the formula below in cells B2, C2, etc



=IF (COUNTIF ($C2:$Z2,$B$1) >0, "YES","") (copy down to each cell with a date in Col A)



then in Col B next to the date, every day the person whose name you entered in cell B1 was in, cells B2, C2, D2, etc would have "YES" and the days he wasn't in would be blank
Bobbb
2014-01-22 17:35:57 UTC
Decide how many patients names you have. e.g six

Put each of their names into a cell from B2 through G2



Put data starting in H2 onwards

Now enter into cell A2 '=COUNTIF(H2:H8,"Mark")' (no apostrophes though)



Into B2 the same formula but use the next name i.e '=COUNTIF(H2:H8,"Dave")'

Into C2 the same formula but use the next name i.e '=COUNTIF(H2:H8,"John")'

Into D2 the same formula but use the next name i.e '=COUNTIF(H2:H8,"Mark")' etcetera for all the list of six names



This will count them and give results in Columns B through G


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...