Results 1 to 10 of 23

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

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Forum Guru Rick Rothstein's Avatar
    Join Date
    Feb 2012
    Posts
    662
    Rep Power
    15
    Quote Originally Posted by MATRIXOFFICE View Post
    sheet names are each month so there are 12 sheets containing data in this case JAN FEB MAR etc etc

    Data commences in row 5 down to row 150
    Okay, I did not understand we were talking multiple sheets as well. One more question then. Given each sheet is devoted to a month, is there a need to check every sheet every time the workbook is closed? In other words, would there be any entries for the MAR (and beyond) sheet(s) yet? Also, would there be any entries for months prior to the current month? For example, tomorrow is February 1st... when this workbook is opened on February 1st, would there be any need to check the JAN sheet when it is closed later that day? Please answer both of those questions.

  2. #2
    Junior Member
    Join Date
    Jan 2013
    Posts
    13
    Rep Power
    0
    no its all point in time data capture. there is no need to check past sheets only current sheets in use. there are no future entries as the data
    is based on incidents that occur. we do not know when and what they are of course ..

  3. #3
    Junior Member
    Join Date
    Jan 2013
    Posts
    13
    Rep Power
    0
    Rick any further advice on this problem?

  4. #4
    Junior Member
    Join Date
    Jan 2013
    Posts
    13
    Rep Power
    0
    Bump## anymore t houghts on this Rick?

  5. #5
    Forum Guru Rick Rothstein's Avatar
    Join Date
    Feb 2012
    Posts
    662
    Rep Power
    15
    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.

  6. #6
    Junior Member
    Join Date
    Jan 2013
    Posts
    13
    Rep Power
    0
    no probs Rick will try it out

  7. #7
    Junior Member
    Join Date
    Jan 2013
    Posts
    13
    Rep Power
    0
    NO good rick can I send you the actual file and you can look at it?

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
  •