+ Reply to Thread
Results 1 to 3 of 3

excel vba for multiple worksheet

  1. #1
    Registered User
    Join Date
    01-17-2014
    Location
    United States
    MS-Off Ver
    Excel 2003
    Posts
    2

    excel vba for multiple worksheet

    Hello,

    I am new to this forum with very little knowlwdge in vb. I have a workbook with several tabs. I have an error checking/validation and "BeforeSave" macro that works for one worksheet. This worksheet and several other are basically same for data entry but different names like "ABC1", "ABC2" and so on. This workbook is distributed out so some users will populate only ABC1 tab and some others may be more than one tab. I would like to run this macro only on tabs that are used for data entry or you may say active tabs only. I appreciate the help.

    Thanks

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: excel vba for multiple worksheet

    insert some lines like this at the start of your macro.

    This will cause the macro to exit if the wrong sheet is active.

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    01-17-2014
    Location
    United States
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: excel vba for multiple worksheet

    Below is the code I tried but is not working...
    I have 15 worksheets in a workbook, 10 are names "ALPHA1", "ALPHA2" and so on and 5 other differently named. Data entry person will enter data into these ALPHA worksheets and enters data. When data entry is finished they will want to save. If they have not entered data into certain fileds then they will not be able to save their work and for this validation part is place and it works (If Trim... already tested). Some data entry person may enter into only 1 worksheet and some may enter into more than one. So each ALPHA worksheet that was populated needs to be checked thru validation.

    Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    Dim wks As Worksheet
    For Each wks In ActiveWorkbook.Worksheets
    If UCase(Left(wks.Name, 5)) = "ALPHA" Then
    wks.Select
    If Trim(ActiveWorkbook.Worksheets("wks").Range("A200")) <> 0 Then
    If Trim(ActiveWorkbook.Worksheets("wks").Range("B200")) < 6 Then Cancel = True
    If Cancel = True Then _
    MsgBox "MyMsg. "
    End If
    End If
    Next wks
    End Sub


    thanks
    vjraman

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Merging multiple excel files in a folder into one master worksheet in a new worksheet
    By johnny_canuck in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 08-22-2013, 12:20 PM
  2. [SOLVED] Combine multiple (100+) excel files w/ one worksheet each into one giant worksheet
    By justin11 in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 08-03-2013, 01:05 PM
  3. Copy and Paste excel data worksheet from multiple workbooks to one Excel sheet...
    By Elle210 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-28-2012, 06:33 PM
  4. merging multiple excel worksheet into 1 worksheet
    By jimb01 in forum Excel General
    Replies: 3
    Last Post: 07-31-2011, 04:25 PM
  5. Replies: 3
    Last Post: 03-12-2006, 06:00 AM

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