EXCEL VBA的問題?

2016-09-27 6:04 pm
程式碼如下
Sub Worksheet_Change(ByVal Target As Range)
Dim KeyCells As Range
Set KeyCells = Range("B1:C10")
If Range("A1") = "" Then
If Not Application.Intersect(KeyCells, Range(Target.Address)) _
Is Nothing Then
MsgBox "請在A1輸入資料"
End If
'Range(Target.Address).ClearContents
End If
End Sub

如果A1沒有輸入值的話Range("B1:C10")範圍內剛輸入的值,將清除,現在問題是如果清除剛寫的,就會無限循環,請問要更改哪,才不會一直循環
麻煩了

回答 (3)

2016-10-24 2:12 am
.
Sub Worksheet_Change(ByVal Target As Range)
'
Set KeyCells = Application.Intersect([B1:C10], Target)
If [A1] = "" And Not KeyCells Is Nothing Then
KeyCells.ClearContents
MsgBox "請在A1輸入資料"
[A1].Select
End
End If
'
End Sub
2016-10-13 9:05 am
網上查
2016-09-28 7:58 am
MsgBox "請在A1輸入資料"
EXIT SUB


收錄日期: 2021-05-03 13:50:35
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20160927100417AAGROhg

檢視 Wayback Machine 備份