+ Reply to Thread
Results 1 to 6 of 6

Macro to work for all worksheets in a workbook

  1. #1
    Registered User
    Join Date
    02-08-2012
    Location
    Dublin
    MS-Off Ver
    Excel 2003
    Posts
    4

    Macro to work for all worksheets in a workbook

    Hi,

    I needed a Macro to open a workbook automatically in today's cell and I found a macro from CFO.com

    Private Sub Workbook_Open()
    Worksheets("Feb").Select
    x = Day(Date)
    Worksheets("Feb").Columns(2).Find(What:=x, LookIn:=xlValues).Activate
    End Sub

    The problem is my workbook is divided into 12 sheets for each month (Jan, Feb, Mar, etc...) and I would like the macro to apply to work across all sheets without having to change the code.
    How would I do that ?

    I'm no VBA expert and I tried a few combinations but it causes me grief.

    Thanks
    Gaetan

  2. #2
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Macro to work for all worksheets in a workbook

    You need to read the forum rules and put code tags around your code, like this...

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    02-08-2012
    Location
    Dublin
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Macro to work for all worksheets in a workbook

    Quote Originally Posted by Andrew-R View Post
    You need to read the forum rules and put code tags around your code, like this...

    Please Login or Register  to view this content.

    Andrew, many thanks for this. I didn't read the forum rules indeed but the amount of time I've been researching to get this when you're not a programmer and when you don't have english as 1st language makes it quite difficult. These are simple things that make our lives easier and something I know from everyday is that if you want something done, just do it yourself.

    Much appreciated for the help
    Best regards

  4. #4
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: Macro to work for all worksheets in a workbook

    Try this

    Please Login or Register  to view this content.

  5. #5
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Macro to work for all worksheets in a workbook

    mrice, expect to hear from my lawyer regarding this blatent infringement of copyright

    Edited to add: As I forgot to copyright my code I am willing to settle out of court for half a lager shandy and a packet of pork scratchings.

  6. #6
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: Macro to work for all worksheets in a workbook

    Obviously didn't read your post closely enough as I didn't notice that your example of code tags also contained a solution.

    Good to see that we came up with the same solution.

    Not sure about your taste in bar snacks...

+ 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