[英]Data clearing when using Target to update range
I have the following macro我有以下宏
Dim rng As Range
Set rng = Target.Parent.Range("D31")
If Target.Address <> rng.Address Then Exit Sub
Select Case rng.Value
Case "N/A": Result = "N/A"
Case "NA": Result = "N/A"
Case "": Result = ""
End Select
Range("E31, G31, H31, I31, J31, K31") = Result
End Sub
When I initially type a value in D31 that is not NA and then type a value in E31, I see the data in E31.当我最初在 D31 中键入一个不是 NA 的值,然后在 E31 中键入一个值时,我在 E31 中看到了数据。 But if I update D31 (ie original value red, new vale read and blue), the value in E31 is erased.
但是,如果我更新 D31(即原始值红色、新值读取和蓝色),则 E31 中的值将被删除。 Is there a way to stop this from happening?
有没有办法阻止这种情况发生?
Range("E31, G31, H31, I31, J31, K31") = Result
inside a conditionRange("E31, G31, H31, I31, J31, K31") = Result
放入条件中If Target.Value = "" Or Result <> ""
. If Target.Value = "" Or Result <> ""
。rng
variable which seems not needed.rng
变量。If Target <> Range("D31") Then Exit Sub
Select Case Target.Value
Case "N/A": Result = "N/A"
Case "NA": Result = "N/A"
Case "": Result = ""
End Select
If Target.Value = "" Or Result <> "" Then
Range("E31, G31, H31, I31, J31, K31") = Result
End If
Now values E31, G31, H31, I31, J31, K31
only change when you input "N/A", "NA" or "" into D31
.现在
E31, G31, H31, I31, J31, K31
值仅在您在D31
中输入“N/A”、“NA”或“”时才会发生变化。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.