0

サブを作りました。しかし、エラーが発生します。列 A に値があるかどうかを確認したい場合は、列「 H と I 」をチェックします。それらは満たされなければなりません。それ以外の場合、ファイルは保存されません.. !!

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    Dim cell As Range
    Dim LastRow As Long
    Dim oneRange As Range
    Dim aCell As Range

    LastRow = Cells(Rows.Count, "A").End(xlUp).Row

    If cell.Value(Range("A8:A" & LastRow)) Is Nothing Then
        Exit Sub
    Else
        For Each cell In Range("H8:I" & LastRow)
            If IsEmpty(cell.Value) Then
                MsgBox "Please Select Value from Dropdown Menu...." & cell.Address
                Application.Goto cell
                Cancel = True
                Exit For
            End If
        Next cell

    End If
End Sub
4

2 に答える 2

1

試行錯誤

これはあなたがしようとしていることですか?

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    Dim ws As Worksheet
    Dim lRow As Long
    Dim aCell As Range

    Set ws = ThisWorkbook.Sheets("receivings")

    With ws
        lRow = .Range("A" & .Rows.Count).End(xlUp).Row

        If Application.WorksheetFunction.CountA(.Range("A8:A" & lRow)) = 0 _
        Then Exit Sub

        For Each aCell In Range("H8:I" & lRow)
            If IsEmpty(aCell.Value) Then
                MsgBox "Please Select Value from Dropdown Menu...." _
                & aCell.Address

                Application.Goto aCell
                Cancel = True
                Exit For
            End If
        Next aCell
    End With
End Sub
于 2013-11-05T14:03:08.427 に答える