+ Reply to Thread
Results 1 to 11 of 11

Help with a Private Sub Workbook_Open

  1. #1
    Forum Contributor
    Join Date
    08-14-2012
    Location
    Derby, England
    MS-Off Ver
    Excel 2010
    Posts
    257

    Help with a Private Sub Workbook_Open

    Hi,

    I am trying to get a code to work:

    Please Login or Register  to view this content.
    What I'm trying to get it to do is if the date appears in Column 2 of the workbook "Rota" for the code to then Select the cell of the match of Extract 2 R1 in Rota column 1 and if the date isnt in Column 2 to do nothing

    I'm thinking:
    Please Login or Register  to view this content.
    is wrong and i might need and "Else Goto" somewhenre in there.

    Thanks in advance. John

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 365 on Win11 (365 on Win11 (desktop), 365 on Win11 (notebook)
    Posts
    8,207

    Re: Help with a Private Sub Workbook_Open

    Hi, John,

    please try:
    Please Login or Register  to view this content.
    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Forum Contributor
    Join Date
    08-14-2012
    Location
    Derby, England
    MS-Off Ver
    Excel 2010
    Posts
    257

    Re: Help with a Private Sub Workbook_Open

    Hi Holger, this is what I had before but because the way my file works I wanted it to open on the week that contained the date so I changed it where it looks at cell that contains the Week number as the week number is in column A. The problem is, as the file is being future proofed, lets say this week is Week 39 of the year, but its being used for next years rota it opens on Week 39 every time I open next years book. I am making this for other people to use and I dont want to disable the code then re-enable when next year starts

  4. #4
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 365 on Win11 (365 on Win11 (desktop), 365 on Win11 (notebook)
    Posts
    8,207

    Re: Help with a Private Sub Workbook_Open

    Hi, John,

    I canīt tell from not seeing the file but maybe the date is the same in both workbooks? Please have a look at the sample I attached where the macro assigned to each sheet works the way we would expect it work.

    Ciao,
    Holger
    Attached Files Attached Files

  5. #5
    Forum Contributor
    Join Date
    08-14-2012
    Location
    Derby, England
    MS-Off Ver
    Excel 2010
    Posts
    257

    Re: Help with a Private Sub Workbook_Open

    Hi Holger - Thanks for taking the time to respond

    I have attached an example of the layout I'm dealing with: Copy of EF909993.xlsm

    This is the code I had before:

    Please Login or Register  to view this content.
    This works in that if I open the book today it will go to "Week 39" as today is in Week 39 - but because I am opening next years file I dont want it to go to Week 39 and want it to do nothing. Hope this makes sense in what I'm trying to get to do. Its the same file that is going to be used for all future years and this year (as the dates in the actual file actually from the Data sheet anyway as that data is imported from a UNIX based data extract that is emailed to the user in a txt file and then is pasted into the Data tab. I'm trying to make it easy in that I can have 1 master file for all years and dont have to change/turn off code every year for ever user of this file!

    Thanks

    John

  6. #6
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 365 on Win11 (365 on Win11 (desktop), 365 on Win11 (notebook)
    Posts
    8,207

    Re: Help with a Private Sub Workbook_Open

    Hi, John,

    to be quite honest: I do not have a clue what you are after.

    The worksheet shows dates starting from June of this year. If I run a check for the actual date there is defeinitely no match as the current date isnīt covered there. The formula inserted in Sheet Data Range A1 doesnīt work for me and errors out and there is no relation (to what I can see) between Data and Rota (okay, maybe VBA code I canīt find).

    Ciao,
    Holger

  7. #7
    Forum Contributor
    Join Date
    08-14-2012
    Location
    Derby, England
    MS-Off Ver
    Excel 2010
    Posts
    257

    Re: Help with a Private Sub Workbook_Open

    Hi Holger,

    Please have a look at the updated file - when you press the button it goes to Week 39. I dont want it to unless today's date is in Column B of Rota. So next year on 26/03 when I open the Rota it will!

    Cheers

    John
    Attached Files Attached Files

  8. #8
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 365 on Win11 (365 on Win11 (desktop), 365 on Win11 (notebook)
    Posts
    8,207

    Re: Help with a Private Sub Workbook_Open

    Hi, John,

    starting this thread you were looking for a date, now youīre looking for a week number. Code will only work for me if I change Date A1 to
    Please Login or Register  to view this content.
    You should include a check for the first date in Rota as well because the code will jump to week 39 although the dates actually do not match.

    Ciao,
    Holger

  9. #9
    Forum Contributor
    Join Date
    08-14-2012
    Location
    Derby, England
    MS-Off Ver
    Excel 2010
    Posts
    257

    Re: Help with a Private Sub Workbook_Open

    Thats what I was trying to figure out in the code in the first post:

    Please Login or Register  to view this content.
    The underlined bit it the bit I think is wrong and needed help with.

    Thanks

    John

  10. #10
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 365 on Win11 (365 on Win11 (desktop), 365 on Win11 (notebook)
    Posts
    8,207

    Re: Help with a Private Sub Workbook_Open

    Hi, John,

    why not compare the first and the last cells of Dates in Column B on Rota to Date?
    Please Login or Register  to view this content.
    So the code should only run in the time limited by these cells which may be altered to suit better.

    Ciao,
    Holger

  11. #11
    Forum Contributor
    Join Date
    08-14-2012
    Location
    Derby, England
    MS-Off Ver
    Excel 2010
    Posts
    257

    Re: Help with a Private Sub Workbook_Open

    Thanks once again Holger - worked fantastic.

+ 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