사용자 양식이 특정 표본 ID (열 AV)에 대한 워크 시트를 검색하고 열 (T, S 및 W)의 항목을보고하도록하려고합니다. 가급적이면 이러한 항목은 환자 정보 확인 (명령 버튼)을 클릭 한 후 메시지 상자에 표시됩니다. 이것이 물리적 테스트 항목과 일치하면 사용자는 AS 열의 정보를 업데이트하는 Combobox에서 테스트 결과를 업데이트해야합니다.
사용할 올바른 코딩을 찾는 데 어려움이 있습니다. 처음에는 텍스트 상자를 사용하는 대신 확인 된 환자 정보 팝업을 메시지 상자로 사용하려고 생각했지만 VBA 코딩에 일치 및 색인 기능을 입력하는 방법을 잘 모르겠습니다. 그리고이 시나리오에서 일치 / 인덱스를 사용하는 방법도 모르겠습니다. Vlookup은 오른쪽으로 검색 할 때만 작동한다는 것을 알고 있습니다.
VBA 사용자 양식 및 코딩 https://www.filedropper.com/dummytest가 포함 된 예제 통합 문서
다음은 해당 사용자 양식에 대한 전체 코드입니다.
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
여기에있는 텍스트 상자가 적을수록 좋습니다.
내가 원하는 것을 수행하도록 코드를 업데이트했습니다. 전체 코드를 붙여 넣어 전체 코드를 사용자 양식 코드에 다시 넣을 수 있습니다.
참고 :
Private Sub CmdBResult_Save_Click()
.Private Sub CmdB_Results_Save_Click()
Application.Match
반복하는 대신 일치 하는 것을 찾았습니다. 업데이트해야하는 일치 항목이 하나만있는 경우에만 작동합니다. 어떤 이유로 중복을 찾아야하는 경우 .Find
또는 루프 를 사용하도록 변경해야합니다 .FindResult
표본 ID를 두 번 찾을 필요가 없도록 공용 변수로 입력 했습니다 (한 번은 환자 세부 정보를 얻고 다시 테스트 결과를 업데이트하기 위해).문제가 있으면 알려주세요. 작동해야합니다. 나는 그것을 모두 테스트했습니다.
Public FindResult As Double
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 Double
'Check something has been enetered in SpecimenID
If Len(Txt_Results_SpecimenID.Text) = 0 Then
Exit Sub
End If
FindResult = 0
specimen_id = Txt_Results_SpecimenID.Text
On Error Resume Next
FindResult = Application.Match(specimen_id, Sheets("Entry").Range("AV:AV"), 0) 'Find the matching ID
If FindResult > 0 Then 'FindResult will be greater than 0 if match found. It will be the row that it found it on.
Txt_Results_FName.Text = Worksheets("Entry").Range("T" & FindResult).Value
Txt_Results_LName.Text = Worksheets("Entry").Range("S" & FindResult).Value
Txt_Results_DOB.Text = Worksheets("Entry").Range("W" & FindResult).Value
Else
MsgBox "No matching Specimen ID was found.", vbInformation, "No Result"
Me.CBResult.Value = ""
Txt_Results_FName.Value = ""
Txt_Results_LName.Value = ""
Txt_Results_DOB.Value = ""
End If
End Sub
Private Sub CmdB_Results_Save_Click()
'copy values to sheet.
Dim Result As String
If Len(Txt_Results_SpecimenID.Text) = 0 Then
MsgBox "There is no Specimen ID entered. The patient info cannot be updated without this identifier.", vbExclamation, "Please enter Specimen ID"
Exit Sub
ElseIf FindResult = 0 Then
MsgBox "The Specimen ID has not been searched for. Please do this before trying to update the patient info.", vbExclamation, "Please enter Specimen ID"
Exit Sub
ElseIf CBResult.Value = "" Then
MsgBox "Please select a test result from the options.", vbExclamation, "Select a test result"
Exit Sub
End If
Worksheets("Entry").Range("AS" & FindResult).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
Private Sub Txt_Results_SpecimenID_Change()
Dim ID As String
ID = Txt_Results_SpecimenID.Text
'This will only allow numbers to be entered into the Specimen ID box
If Not IsNumeric(Right(ID, 1)) Then
If Len(ID) = 0 Then Exit Sub
Txt_Results_SpecimenID.Text = Left(ID, Len(ID) - 1)
End If
End Sub
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다