Page 3 of 3 FirstFirst 123
Results 21 to 23 of 23

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

  1. #21
    Junior Member
    Join Date
    Jan 2013
    Posts
    13
    Rep Power
    0
    file size exceed forum limit so I will email thanks Rick

  2. #22
    Forum Guru Rick Rothstein's Avatar
    Join Date
    Feb 2012
    Posts
    662
    Rep Power
    13
    To keep this thread updated...

    I received the file from MATRIXOFFICE and found that the cells in Columns M thru O had formulas in the, so my use of WorksheetFunction.CountA was not working. I sent the following code to MATRIXOFFICE which worked in my tests, so I expect it is the code that he will end up using...
    Code:
    Private Sub Workbook_BeforeClose(Cancel As Boolean)
      Dim Mnths As Long, Rws As Long, BlankCellCount 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
            BlankCellCount = WorksheetFunction.CountIf(WS.Cells(Rws, "M").Resize(, 3), "")
            If BlankCellCount 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

  3. #23
    Junior Member
    Join Date
    Jan 2013
    Posts
    13
    Rep Power
    0
    Rick thanks it works a treat!

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
  •