I am trying to have a userform search a worksheet for the specific specimen_ID (column AV) and report back items in Columns (T, S, and W). Preferably, these items would show up in a message box after clicking verify patient info (command button). If these match on the physical test item, then the user would need to update the test result from a Combobox which updates info in column AS.
I'm having difficulty finding the correct coding to use. I initially thought to just have the verified patient info pop-up as a message box instead of using text boxes, but I wasn't sure how to input match and index functions into the VBA coding. And I also am not sure how to use match/index in this scenario. I know that Vlookup only works when searching to the right.
Example workbook with the VBA user forms and coding https://www.filedropper.com/dummytest
Here's the whole code for that user form.
Private Sub CBResult_Enter()
Me.CBResult.Clear
Me.CBResult.AddItem "Detected/Positive"
Me.CBResult.AddItem "Not detected/Negative"
Me.CBResult.AddItem "Inconclusive/Undetermined/Invalid/Equivocal"
End Sub
Private Sub CmdB_Results_Verify_Click()
Dim specimen_id As String
specimen_id = Trim(Txt_Results_SpecimenID.Text)
lastrow = Worksheets("Entry").Cells(Rows.Count, "AV").End(xlUp).Row
For i = 2 To lastrow
If Worksheets("Entry").Cells(i, 1).Value = specimen_id Then
Txt_Results_FName = Worksheets("Entry").Cells(i, "T").Value
Txt_Results_LName = Worksheets("Entry").Cells(i, "S").Value
Txt_Results_DOB = Worksheets("Entry").Cells(i, "W").Value
End If
Next
End Sub
Private Sub CmdBResult_Save_Click()
'copy values to sheet.
Dim Result As String
Result = CBResult.Value
lastrow = Worksheets("Entry").Cells(Rows.Count, "AV").End(xlUp).Row
For i = 2 To lastrow
If Worksheets("Entry").Cells(i, 1).Value = Txt_Results_specimen_id.Value Then
Worksheets("Entry").Cells("AS").Value = CBResult.Value
'Clear input Controls.
Me.CBResult.Value = ""
Txt_Results_FName.Value = ""
Txt_Results_LName.Value = ""
Txt_Results_DOB.Value = ""
End Sub
Private Sub CmdB_Results_Close_Click()
'Close "ResultsEntry"
Unload Me
End Sub
The fewer text boxes I have here the better.