gpt4 book ai didi

excel - 合并两个 Private Sub Worksheet_Change(ByVal Target As Range)

转载 作者:行者123 更新时间:2023-12-04 20:32:27 24 4
gpt4 key购买 nike

我需要合并两个 Private Sub Worksheet_Change(ByVal Target As Range)我是 Excel VBA 代码的新手,我该怎么做?代码如下。

Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng As Range, r As Range, rv As Long
Set rng = Intersect(Target, Range("C77:AD81"))
If rng Is Nothing Then Exit Sub
For Each r In rng
rv = r.Value
'Peak Flow Doctor Warning and Weight Gain Warning
If rv = 180 Then
MsgBox "''PEAK FLOW CRITICAL AT 180L/MIN''" & vbCrLf & "''PREDNISONE PROBABLY REQUIRED''" & vbCrLf & "''MAKE DOCTOR'S APPOINTMENTS ASAP''", vbInformation, "WARNING"
End If
If rv = 120 Then
MsgBox "''PEAK FLOW CRITICAL AT 120L/MIN''" & vbCrLf & "''MAKE URGENT DOCTOR'S APPOINTMENTS''" & vbCrLf & "''OR GO TO A&E IMMEDIATELY''", vbInformation, "CRITICAL WARNING"
End If
If rv >= 450 Then
MsgBox "''CHECK OR TEST PEAK FLOW METER''" & vbCrLf & "''IT MAY BE FAULTY AND GIVING FALSE HIGH's''", vbInformation, "WARNING"
End If


Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng As Range, r As Range, rv As Long
Set rng = Intersect(Target, Range("C93:AD93"))
If rng Is Nothing Then Exit Sub
For Each r In rng
'Weight Gain Warning
rv = r.Value
If rv = 90 Then
MsgBox "''LIKELY TO EXACERBATE COPD SYMPTOMS''" & vbCrLf & "''CHRONIC ASTHMA OR EMPHYSEMA PROBABLE''", vbCritical, "WARNING"
End If
If rv = 95 Then
MsgBox "''IF SWELLING IN ANKLES PROBABLE FLUID RETENTION''" & vbCrLf & "''POSSIBILITY OF HEART FAILURE IF UNATTENDED''", vbCritical, "CRITICAL WARNING"
End If
Next r
End Sub

最佳答案

下面的代码是您当前 2 Worksheet_Change 的合并事件。

您也可以使用Select Case稍微清理一下你的代码。

代码

Private Sub Worksheet_Change(ByVal Target As Range)

Dim rng As Range, r As Range, rv As Long

If Not Intersect(Target, Range("C77:AD81")) Is Nothing Then
Set rng = Intersect(Target, Range("C77:AD81"))
For Each r In rng
'Peak Flow Doctor Warning and Weight Gain Warning
Select Case r.Value
Case 180
MsgBox "''PEAK FLOW CRITICAL AT 180L/MIN''" & vbCrLf & "''PREDNISONE PROBABLY REQUIRED''" & vbCrLf & "''MAKE DOCTOR'S APPOINTMENTS ASAP''", vbInformation, "WARNING"
Case 120
MsgBox "''PEAK FLOW CRITICAL AT 120L/MIN''" & vbCrLf & "''MAKE URGENT DOCTOR'S APPOINTMENTS''" & vbCrLf & "''OR GO TO A&E IMMEDIATELY''", vbInformation, "CRITICAL WARNING"
Case Is >= 450
MsgBox "''CHECK OR TEST PEAK FLOW METER''" & vbCrLf & "''IT MAY BE FAULTY AND GIVING FALSE HIGH's''", vbInformation, "WARNING"
End Select
Next r
End If

If Not Intersect(Target, Range("C93:AD93")) Is Nothing Then
Set rng = Intersect(Target, Range("C93:AD93"))
For Each r In rng
'Weight Gain Warning
Select Case r.Value
Case 90
MsgBox "''LIKELY TO EXACERBATE COPD SYMPTOMS''" & vbCrLf & "''CHRONIC ASTHMA OR EMPHYSEMA PROBABLE''", vbCritical, "WARNING"
Case 95
MsgBox "''IF SWELLING IN ANKLES PROBABLE FLUID RETENTION''" & vbCrLf & "''POSSIBILITY OF HEART FAILURE IF UNATTENDED''", vbCritical, "CRITICAL WARNING"
End Select
Next r
End If

End Sub

关于excel - 合并两个 Private Sub Worksheet_Change(ByVal Target As Range),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47999592/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com