Results 1 to 1 of 1

VBA Code for a Single Sheet

Threaded View

  1. #1
    Registered User
    Join Date
    08-23-2010
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    7

    VBA Code for a Single Sheet

    So im very new to the use of VBA in Microsoft Excel. I have created worksheets for work and mostly through help from online sources have gotten a working code I use.
    The thing is, I want to merge multiple Workbooks together and I need to get my code so it effects only 1 Sheet of a workbook. Otherwise all my sheets conflict and stuff.

    I have a Excel document with 2 Sheets
    Sheet1 Venison
    Sheet2 Drops

    Here is the Code for the Workbook.

    Private Sub Workbook_BeforeClose(Cancel As Boolean)
    If ([AC2] = "") Or ([AC3] = "") Or ([D4] = "") Or ([R4] = "") Or ([D5] = "") Or ([N5] = "") Or ([V5] = "") Or ([D6] = "") Or ([M6] = "") Or ([S6] = "") Or _
    ([X6] = "") Then
    MsgBox "Please make sure all Contact Information is filled in:", vbExclamation, "You are missing required information!"
    Cancel = True
    End If
    'Instructions By: [AC2]
    'Deer #: [AC3]
    'Name: [D4]
    'License #: [R4]
    'Phone #: [D5]
    'Alt. Ph. #: [N5]
    'Email: [V5]
    'Address: [D6]
    'City: [M6]
    'State: [S6]
    'Zip: [X6]
    'Animal: [D7]
    End Sub
    
    Private Sub Workbook_BeforePrint(Cancel As Boolean)
    If ([AC2] = "") Or ([AC3] = "") Or ([D4] = "") Or ([R4] = "") Or ([D5] = "") Or ([N5] = "") Or ([V5] = "") Or ([D6] = "") Or ([M6] = "") Or ([S6] = "") Or _
    ([X6] = "") Then
    MsgBox "Please make sure all Contact Information is filled in:", vbExclamation, "You are missing required information!"
    Cancel = True
    End If
    End Sub
    
    Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    If ([AC2] = "") Or ([AC3] = "") Or ([D4] = "") Or ([R4] = "") Or ([D5] = "") Or ([N5] = "") Or ([V5] = "") Or ([D6] = "") Or ([M6] = "") Or ([S6] = "") Or _
    ([X6] = "") Then
    MsgBox "Please make sure all Contact Information is filled in:", vbExclamation, "You are missing required information!"
    Cancel = True
    End If
    End Sub
    I want this Code to only effect Sheet 1, Becuase I want to merge another document that has this code with different positions for its Sheet.

    Long Story Short.

    3 Documents - Sheet1 Venison, Sheet1 Elk, Sheet1Bear. All different workbooks that im merging and need all their code sets to work.
    Last edited by Leith Ross; 09-19-2012 at 07:24 PM. Reason: Added Code Tags

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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