+ Reply to Thread
Results 1 to 3 of 3

Two Cells required before saving or closing.

  1. #1
    Registered User
    Join Date
    07-11-2013
    Location
    Wyoming, USA
    MS-Off Ver
    Excel 2010
    Posts
    3

    Two Cells required before saving or closing.

    Hello everyone, Im new to editing in VB with excel.... Is there a way to make cells C3 (employee name) and C5 (employee ID) required before saving or exiting on excel. We use excel to track days worked and our employees sometime forget to fill these two fields out before submitting to payrole.

  2. #2
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Two Cells required before saving or closing.

    You can use something like this code. Note, it needs to be saved in the ThisWorkbook object in your vba project (Not a new module)
    Please Login or Register  to view this content.
    Last edited by ragulduy; 07-11-2013 at 03:52 AM.

  3. #3
    Registered User
    Join Date
    07-11-2013
    Location
    Wyoming, USA
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Two Cells required before saving or closing.

    Thanks so much yudlugar I used this code:

    Private Sub Workbook_BeforeClose(Cancel As Boolean)
    Dim whatCell As String
    whatCell = "C3"
    If Sheets("Monthly Report").Range(whatCell).Value = "" _
    Or IsEmpty(Sheets("Monthly Report").Range(whatCell)) Then
    MsgBox "Please enter your name in box " & whatCell
    Cancel = True 'cancels the save event
    Exit Sub
    End If
    whatCell = "C5"
    If Sheets("Monthly Report").Range(whatCell).Value = "" _
    Or IsEmpty(Sheets("Monthly Report").Range(whatCell)) Then
    MsgBox "Please enter your SAP in box " & whatCell
    Cancel = True 'cancels the save event
    Exit Sub
    End If
    End Sub

    Now I just need to figure out if you can prompt them to make the changes both before they save and before they exit.

  4. #4
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Two Cells required before saving or closing.

    Put the same thing as a beforesave event:
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    07-11-2013
    Location
    Wyoming, USA
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Two Cells required before saving or closing.

    Nevermind I got it, thank you so much

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1