這段代碼用于我在作業中所做的事情,它輸出“沒有患者參考!” 在一個 MsgBox 中。如果我洗掉檢查單元格是否為 IsEmpty 的 if,我會在 MsgBox 中得到“未找到患者”。好像我錯過了一些東西,我不確定是什么,有人可以幫忙嗎?
Private Sub CommandButton2_Click()
Dim emptytest2 As Boolean
emptytest2 = IsEmpty(Sheet1.Range("C28").Value)
If emptytest2 = False Then
MsgBox "No patient reference!"
End
End If
Dim found As Range
Dim band1 As Range
Dim foundoff As Range
Set found = Sheet2.Columns("B").Find(what:=Sheet1.Range("C28").Value, LookIn:=xlValues, lookat:=xlWhole)
If Not found Is Nothing Then
Set band1 = Sheet1.Range("C29")
MsgBox found & " - Data found for patient in cell " & found.Address
Set foundoff = Range(found.Address).Offset(, 30)
band1.Copy
Sheet2.Range(foundoff.Address).PasteSpecial
Else
MsgBox "Patient not found"
End
End If
MsgBox "Successfully added band cutoff data to " & found
End Sub
uj5u.com熱心網友回復:
Option Explicit
Private Sub CommandButton2_Click()
Dim ref As Range, found As Range, rng As Range
Set ref = Sheet1.Range("C28")
If Len(ref.Value) = 0 Then
MsgBox "No patient reference!", vbExclamation
Exit Sub
End If
Set found = Sheet2.Columns("B:B").Find(what:=ref.Value, _
LookIn:=xlValues, lookat:=xlWhole)
If found Is Nothing Then
MsgBox "Patient Ref '" & ref.Value & "' not found", vbExclamation
Exit Sub
Else
Set rng = found.Offset(, 30) ' col AF
rng.Value = ref.Offset(1) ' C29
MsgBox "Patient Ref: '" & ref.Value & "' found in cell " & found.Address
End If
MsgBox "Successfully added " & rng.Value & " to " & rng.Address
End Sub
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/415477.html
標籤:
