Results 1 to 10 of 23

Thread: VBA Stop Workbook From Closing Unless Data Is Filled Complete

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #11
    Forum Guru Rick Rothstein's Avatar
    Join Date
    Feb 2012
    Posts
    662
    Rep Power
    14
    Quote Originally Posted by MATRIXOFFICE View Post
    Bump## anymore t houghts on this Rick?
    Sorry about my absence. See if this code will do what you want...
    Code:
    Private Sub Workbook_BeforeClose(Cancel As Boolean)
      Dim Mnths As Long, Rws As Long, FilledCellCount As Long, WS As Worksheet
      For Mnths = 1 To 12
        Set WS = Worksheets(UCase(Format(28 * Mnths, "mmm")))
        For Rws = 5 To 150
          If Len(WS.Cells(Rws, "G").Value) Then
            FilledCellCount = WorksheetFunction.CountA(WS.Cells(Rws, "M").Resize(, 3))
            If FilledCellCount <> 3 Then
              Cancel = True
              MsgBox "Please check Row #" & Rws & " on sheet """ & WS.Name & """" & _
                     vbLf & vbLf & "You have an incident filled in Column G for that row " & _
                     "but you are missing one or more pieces of data in Columns M thru O"
              WS.Activate
              Cells(Rws, "M").Resize(, 3).Select
              Exit Sub
            End If
          End If
        Next
      Next
    End Sub
    Last edited by Rick Rothstein; 03-17-2013 at 08:31 PM.

Similar Threads

  1. Replies: 17
    Last Post: 05-22-2013, 11:58 PM
  2. Auto Complete for Data Validation
    By IJC in forum Excel Help
    Replies: 1
    Last Post: 05-15-2013, 09:30 AM
  3. Replies: 2
    Last Post: 12-04-2012, 02:05 PM
  4. VBA Code to Open Workbook and copy data
    By Howardc in forum Excel Help
    Replies: 16
    Last Post: 08-15-2012, 06:58 PM
  5. VBA code to copy data from source workbook
    By Howardc in forum Excel Help
    Replies: 1
    Last Post: 07-30-2012, 09:28 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •