Move to next row and repeat

eviehc123

New Member
Joined
Jan 21, 2019
Messages
32
Hi,

How can I edit this code to repeat the check on the next row? I would like the code to check ranges B3:B9, B12:B18, B21:B27, B30:B36, L3:L9 before closing to ensure that the user cannot close the form before editing all cells.

I should note that usually only one row will be completed at a time before closing.

Thanks!

Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
    If ActiveSheet.Range("B3") <> "" And _
    ActiveSheet.Range("C3") = "" And _
    ActiveSheet.Range("D3") = "" And _
    ActiveSheet.Range("E3") = "" And _
    ActiveSheet.Range("F3") = "" And _
    ActiveSheet.Range("G3") = "" And _
    ActiveSheet.Range("H3") = "" Then
        Cancel = True
        MsgBox "All cells must be completed"
    Else
        ActiveWorkbook.Close SaveChanges:=True
    End If
End Sub
 
Hi thank you. I have placed both codes in Thisworkbook. However, it will not let me close even if a whole row has been completed? I want it to save close after one row has been completed if possible.
 
Upvote 0

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Hi thank you. I have placed both codes in Thisworkbook. However, it will not let me close even if a whole row has been completed? I want it to save close after one row has been completed if possible.

That's what updated function should do. The function will highlight the row that is only part completed.
check all cells in your defined range to ensure they are clear.

If still having issues then if possible, place copy of your workbook in a dropbox & provide a link to it here.

Dave
 
Upvote 0
Hi,
Two things

1 - you have the function in Module 1 & ThisworkBook Module - delete them BOTH

2 - Replace in either location the following updated function

Code:
Function IsNotComplete() As Boolean
    Dim Cell As Range, Rng As Range
    Dim Target As Range
    
    Set Target = Range("B3:B9,B12:B18,B21:B27,B30:B36,L3:L9")
    
    For Each Cell In Target.Cells
        Set Rng = Cell.Resize(, 7)


        With Application
            If .CountIf(Rng, ">""") Then
                IsNotComplete = CBool(.CountA(Rng) <> Rng.Cells.Count)
            End If
        End With
        
        If IsNotComplete Then
            MsgBox "All cells must be completed", 48, "Entry Required"
            Rng.Select
            Exit Function
        End If
        Set Rng = Nothing
    Next Cell
End Function

What you did not mention is that some cells in your ranges have formulas which were being counted as an entry even though cell showing blank.

Hopefully, updated version will resolve.

Dave
 
Upvote 0

Forum statistics

Threads
1,223,230
Messages
6,170,883
Members
452,364
Latest member
springate

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top