簡體   English   中英

Worksheet_Change(ByVal faixa As Range)在范圍為空的情況下停止宏

[英]Worksheet_Change(ByVal faixa As Range) stop macro in case the range in empty

我已經在工作表中運行以下代碼,並且如果行為空,我需要停止運行它。 請注意,當該行為空白時,我需要停止顯示日期或讓我在A列(1)中刪除它。 事實是,當我刪除行中的數據時,我無法刪除A列中的日期-宏正在運行並且不能讓我這樣做。

Sub Worksheet_Change(ByVal faixa As Range)
Dim dados As Range
Set dados = Range("A1:AI400")
If Not Intersect(faixa, dados) Is Nothing Then
Application.EnableEvents = False
dados.Cells(faixa.Row, 1).Value = Date
Application.EnableEvents = True
End If
End Sub

聽起來好像您的代碼正在運行,即使您打算在沒有理解的情況下保留空白單元格時也是如此。 要更正它,以下內容將允許您保留一個空白單元格:

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal faixa As Range)

Dim dados As Range
Set dados = Range("A1:AI4000")

If Not Intersect(faixa, dados) Is Nothing Then
     If Not faixa = "" Then
        dados.Cells(faixa.Row, 1).value = Date
     End If
End If
End Sub

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM