【问题标题】:Dynamic Loop Range, VBA动态循环范围,VBA
【发布时间】:2020-11-15 15:11:15
【问题描述】:

我正在创建宏 Excel,它将在关闭工作簿之前检查特定范围内是否有空单元格。我有一个问题,范围是动态的,并且我有一个包含我每次要检查的范围的单元格,我如何使用 VBA 中的单元格值作为范围。

这是VBA

Private Sub Workbook_BeforeClose(取消为布尔值) 对于范围内的每个单元格(“A2:E2”) 如果 cell.Value = "" 那么 MsgBox "请填写空白单元格", vbInformation, "警告" 单元格.选择 取消 = 真 退出子 万一 下一个 结束子

Private Sub Workbook_Open()

结束子


谢谢

【问题讨论】:

    标签: excel vba


    【解决方案1】:

    试试这个代码

    Private Sub Workbook_BeforeClose(Cancel As Boolean)
        Dim e, cell As Range
        e = Range("O11").Value
        If IsNumeric(Evaluate("SUM(" & e & ")")) And Not IsNumeric(e) Then
            For Each cell In Range(e)
                If cell.Value = "" Then
                    MsgBox "Please, Fill Empty Cells", vbInformation, "Warning"
                    cell.Select
                    Cancel = True: Exit Sub
                End If
            Next cell
        End If
    End Sub
    

    【讨论】:

      猜你喜欢
      • 2018-05-07
      • 2015-08-03
      • 2019-03-29
      • 1970-01-01
      • 1970-01-01
      • 2021-10-02
      • 1970-01-01
      • 1970-01-01
      • 2019-06-16
      相关资源
      最近更新 更多