Consulting

Results 1 to 5 of 5

Thread: Solved: Restrict user to close the file if a cell is blank

  1. #1

    Solved: Restrict user to close the file if a cell is blank

    When the user updates data in column F in a cell range, he has to compulsorily update the target date (Column H) in the corresponding cell range also.

    Say, If the user updates data in cell F7 and not updated the target date in cell H7 and closes the file, an alert message has to pop-up (Ok). If the user click OK, the close book event has to be disabled.

    I attached the sheet.

    Raj

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Private Sub Workbook_BeforeClose(Cancel As Boolean)
    Dim msg As String
    Dim i As Long

    With Worksheets("Action item tracker")

    For i = 2 To .Cells(.Rows.Count, "F").End(xlUp).Row

    If .Cells(i, "F").Value <> "" And .Cells(i, "H").Value = "" Then

    msg = msg & "Row #" & i & vbNewLine
    End If
    Next i

    If msg <> "" Then

    MsgBox "Incomplete data" & vbNewLine & vbNewLine & msg
    Cancel = True
    End If
    End With
    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    this works fine. thank you.

  4. #4
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Please remember to mark your threads Solved.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  5. #5
    Marked the thread as Solved.
    Thanks.

Posting Permissions

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