Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 将单元格转换为关闭前VBA中的一系列单元格_Excel_Vba - Fatal编程技术网

Excel 将单元格转换为关闭前VBA中的一系列单元格

Excel 将单元格转换为关闭前VBA中的一系列单元格,excel,vba,Excel,Vba,我已经查看并尝试了所有数组和set函数,但当我在程序中运行它时,它不起作用。 这是我的节目 Private Sub Workbook_BeforeClose(Cancel As Boolean) If Sheets("Check").Range("G16").Value = "Special Request" And _ Range("G17").Value = "" Or _ Range("G18").Value = "" Or _ Range("G19").Value = "" Or _ R

我已经查看并尝试了所有数组和set函数,但当我在程序中运行它时,它不起作用。 这是我的节目

Private Sub Workbook_BeforeClose(Cancel As Boolean)
If Sheets("Check").Range("G16").Value = "Special Request" And _
Range("G17").Value = "" Or _
Range("G18").Value = "" Or _
Range("G19").Value = "" Or _
Range("G20").Value = "" Then
MsgBox "Please verify that all tabs are check using the check tab"
Cancel = True
End If
End Sub
我想插入范围,而不是命名每个单元格。例如:; G17:G20或 G24:G29或 G33:G38呢_


如果有人有任何建议,我们将不胜感激

使用
工作表函数.CountA()
计算范围内非空白值的数量,并将其与范围单元格计数进行比较

Private Sub Workbook_BeforeClose(Cancel As Boolean)
    Dim Target As Range
    Set Target = Range("G17:G20,G33:G38")
    If Sheets("Check").Range("G16").Value = "Special Request" And _
        WorksheetFunction.CountA(Target) < Target.count Then

        MsgBox "Please verify that all tabs are check using the check tab"
        Cancel = True
    End If
End Sub
Private子工作簿\u关闭前(取消为布尔值)
作为射程的弱小目标
设定目标=范围(“G17:G20,G33:G38”)
如果图纸(“检查”)范围(“G16”).Value=“特殊要求”和_
工作表function.CountA(Target)
您的第一个范围相对于工作表“检查”,但其他范围相对于活动工作表。