+ Reply to Thread
Results 1 to 16 of 16

VBA to 'on open' of workbook look at all sheets for 'OVERDUE' and transfer to Main Report

  1. #1
    Registered User
    Join Date
    03-06-2013
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    31

    VBA to 'on open' of workbook look at all sheets for 'OVERDUE' and transfer to Main Report

    Hello,

    I've scoured the internet for what seems decades today, in and out of forests of code and macros that I 'sometimes get' and 'mostly don't get'. I am using Microsoft 2010 and have limited understanding of VBA.

    I'm trying to do 2 simple actions. When opening the Workbook - have the workbook automatically search itself to find any field that is listed as either 'OVERDUE' or 'DUE' onto two separate report sheets.

    [Edit - I need the WHOLE LINE to be copied across to either report page, once it's been listed as either overdue or due]

    I'm not concerned if I have to copy a code to each individual sheet so that it transfers the data over, I just need help in understanding how to write exactly what it is that I want it to do.

    My workbook has 9 sheets that I want the information to be trawled through to find, for ease of understanding at this stage, I've just unhidden two of them, the main register page, and the two sheets that I'd like the information to be transposed onto.

    Is there anyone out there who can help me? (Pete_UK - you seem to have a good knack of things, but I didn't know if I was allowed to contact directly)

    Kind regards
    Pip

    HHTS-REG-002 v2.0 Document Control Register.xls
    Last edited by PippiLaRue; 03-06-2013 at 03:26 AM.

  2. #2
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: VBA to 'on open' of workbook look at all sheets for 'OVERDUE' and transfer to Main Rep

    1) I do not find on your workbook any cell with overdue
    2) I did not understand where copy rows with overdue
    If solved remember to mark Thread as solved

  3. #3
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: VBA to 'on open' of workbook look at all sheets for 'OVERDUE' and transfer to Main Rep

    Hi, patel45,

    1) I do not find on your workbook any cell with overdue
    Youīre kidding, arenīt you? Sheets Chart, Range("R7").

    Copy the Formula from Chart R7 to Register R7 and drag it down. Then copy all information from either Chart or Register to OverdueDocs or DueDocuments respectively where either OVERDUE or DUE is listed in Column R.

    HTH,
    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

  4. #4
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: VBA to 'on open' of workbook look at all sheets for 'OVERDUE' and transfer to Main Rep

    Quote Originally Posted by HaHoBe View Post
    Youīre kidding, arenīt you? Sheets Chart, Range("R7").
    yes Sir, I missed your advice

  5. #5
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: VBA to 'on open' of workbook look at all sheets for 'OVERDUE' and transfer to Main Rep

    Hi, patel45,

    I doubt this answer will help the Thread Opener in any way - this thread is out of the list of unanswered threads for sure (and still no hints on a solution).

    Maybe you can show your great heart and supply the TO with some coding?

    Ciao,
    Holger
    Last edited by HaHoBe; 03-07-2013 at 03:01 AM. Reason: sorry for typo in name

  6. #6
    Registered User
    Join Date
    03-06-2013
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    31

    Re: VBA to 'on open' of workbook look at all sheets for 'OVERDUE' and transfer to Main Rep

    Hi Guys - yes, some coding would be more specific - just need an easy VBA or Macro that will look up "overdue" and "due" in any of the sheets, and automatically populate, either the DueDocuments or the OverdueDocs sheets. It's pretty simple what I need - I'm just getting lost in finding out what the code is.

    Is Anyone able to help??

  7. #7
    Registered User
    Join Date
    03-06-2013
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    31

    Re: VBA to 'on open' of workbook look at all sheets for 'OVERDUE' and transfer to Main Rep

    Hi Holger,

    Is there any chance that you could possibly help me out with the code? I forgot to add that I need it all to go on the +1 line..

    Pip

  8. #8
    Registered User
    Join Date
    03-06-2013
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    31

    Re: VBA to 'on open' of workbook look at all sheets for 'OVERDUE' and transfer to Main Rep

    Perhaps Pete_UK might be able to lend a hand on this one....?

  9. #9
    Registered User
    Join Date
    03-06-2013
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    31

    Re: VBA to 'on open' of workbook look at all sheets for 'OVERDUE' and transfer to Main Rep

    FRazzled...

  10. #10
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,724

    Re: VBA to 'on open' of workbook look at all sheets for 'OVERDUE' and transfer to Main Rep

    Hi Pip,

    Well, you keep mentioning my name (and sent me a visitor message), but I'm not sure what I've done to instill you with such confidence in my abilities !!

    I tend not to submit macro solutions - mine are usually formula-based, which thus automatically adjust when data is changed or added.

    However, it's getting a bit late here for me to start such a big task, so I'll take a detailed look at it tomorrow. I can see a Status field in the Chart sheet, but not in the Registers sheet. What about your other (hidden) sheets? Please supply a file with all relevant sheets un-hidden, to save me time from searching for them.

    Hope this helps.

    Pete

  11. #11
    Registered User
    Join Date
    03-06-2013
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    31

    Cool Re: VBA to 'on open' of workbook look at all sheets for 'OVERDUE' and transfer to Main Rep

    Thanks Pete! Formulas work for me just as well - actually anything works for me just as well!
    I only added details in the Chart sheet, so that I could get help on one sheet (if it was to be a replication on each sheet) and so I could learn myself for the rest.

    I've unlocked all of the applicable sheets required for this purpose. There are still two hidden sheets, but they don't fall into this category of looping, checking and copying over to worksheets.
    I've also realised that I don't need all of the data to come over - but I've hidden the columns on the reporting sheets, just in case it all gets brought over. Essentially I'm looking to copy only over A:E and J:N, R.

    **sometimes people see and have confidence in the abilities of others because of how they act in these forums, how they help in these forums, and how solutions are identified. That my friend (unrequested friend) is where my confidence comes from - besides that 3,667 posts helps!! ;p **

    HHTS-REG-002 v2.1 Document Control Register - For Coding.xls

  12. #12
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,724

    Re: VBA to 'on open' of workbook look at all sheets for 'OVERDUE' and transfer to Main Rep

    Okay, I've just taken a quick look before I go to bed and I can see that you have a status column (R) in those sheets (but not in the Quality Assurance sheet - is this an oversight?). Also, your status formula will need a bit of tweaking to account for the Days Until Next Review (column Q) being empty - see the Lean sheet, for example.

    I think I will need two helper columns in each of those sheets, one to identify Overdue and the other to identify Due items - once these are set up they can be hidden. I will also need two lookup tables, and I think it might be best to put these in their own sheet. Then in the report sheets I will need two helper columns and a series of INDEX formulae to retrieve appropriate data - should be fairly straightforward.

    There, I've partially solved it already, and I said I would leave it till tomorrow !! <bg>

    Good night.

    Pete
    Last edited by Pete_UK; 03-07-2013 at 09:22 AM. Reason: spelling

  13. #13
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: VBA to 'on open' of workbook look at all sheets for 'OVERDUE' and transfer to Main Rep

    Hi, PippiLaRue,

    itīs essential for any further action to fill in the formula in Column R on any sheet (or have VBA do this). And maybe you should work on that formula to only show values if Column Q is filled.

    You could use Autofilter and SpecialCells(xlCellTypeVisible) to narrow down the amount of cells to walk through, I didnīt do that as well as placing or calling the procedure in or from ThisWorkbook Workbook_Open-event. You should give this a go on a copy of the original workbook:
    Please Login or Register  to view this content.
    I just passed the information from Column A to R, if you want to include the comments from Column S you need to correct the number 19 inside Resize to read 20.

    Ciao,
    Holger
    Last edited by HaHoBe; 03-07-2013 at 02:55 AM. Reason: Info on correcting Resize to work for Column S as well

  14. #14
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,724

    Re: VBA to 'on open' of workbook look at all sheets for 'OVERDUE' and transfer to Main Rep

    Hi Pip,

    you posted your first thread at about 7:20pm my time yesterday, so I figured you'd be up and about now as it is about 8:50pm here - not sure exactly how many hours there are between us. I've put together a formula-based solution to your problem (attached), so a few general comments first:

    As you submitted the file as an .xls, I've saved it in the same format - you get a few warning messages about conditional formatting and colours used, but you can ignore these if you save to the same format. I didn't enable macros, so I didn't look at what you had in there - I suspect they are linked to the buttons on the first sheet to enable a user to jump to other sheets. I've removed all filter settings and also revealed all columns that were hidden, as it is better to be able to see everything and avoid unwanted consequences to formulae or data in hidden columns. I figured you'd be able to set things up as you want them if you are happy that the workbook does its job. I haven't changed any of your data, but I changed the NOW() function to TODAY() in column M, as you only want the date rather than the date/time. I've set most sheets up down to row 30, although a couple of sheets needed more rows. If you need more, then just copy row 30 down into row 31 onwards. I've also set up Freeze Panes on most sheets.

    I've amended the Status formula to this in R7:

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    and I've also set up the conditional formatting using the same colours as in column Q. I decided that you probably would want to include data from the Quality Assurance sheet, so I made the necessary changes to that.

    I've added a new sheet called Lookup_tables, which basically lists the sheet names and the maximum number in columns U and V on each sheet. The general approach that I've taken in this file is to identify records which match the criteria in the Status column, and then set up a simple sequence, which will automatically propagate into the next sheets in line. So if there were three records identified in the first sheet they will be numbered 1, 2, 3, and then in the next sheet the numbering would carry on to 4, 5, 6 etc for other records which match the criteria, and then again into the third sheet.

    To accomplish this I've used columns U and V in each sheet as helpers, with the sheet name in U1 and "Due" and "Overdue" in cells U6 and V6. This is the formula in U7:

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    and the formula is copied into V7 to give this (virtually identical):

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    If the status matches row 6 then a number is incremented, otherwise a hyphen is returned (this helps to show where the formula has been copied to). In the first sheet in the sequence (Quality Assurance) cells U5 and V5 both contain zero, but on other sheets U5 contains this formula:

    =MAX(INDIRECT("'"&INDEX(Lookup_tables!$B:$B,MATCH($U$1,Lookup_tables!$B:$B,0)-1)&"'!U:U"))

    (The formula in V5 is very similar - it just has V:V at the end instead of U:U). This finds the largest number used on the previous sheet, so that the numbering can carry on in sequence. It does this by finding where the sheet name from U1 exists in the lookup tables, and then choosing the one before it, and then looking in column U of that sheet for the largest number. That's the crucial part of it in this situation, getting the sequential numbering established - the other formulae in the reporting sheets are basically INDEX and MATCH.

    I have again used columns U and V on the reporting sheets - column U identifies the sheet and column V the row within that sheet where the sequential numbers occur (i.e. the records which match the criteria. In the DueDocuments sheet this formula is in U7:

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    and this in V7:

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    The first uses the numbers in the lookup tables to identify where ROWS($1:1) exists and returns the appropriate sheet name. Note that the term ROWS($1:1) returns 1 on that row, but as the formula is copied down it becomes ROWS($1:2) then ROWS($1:3), returning 2 and 3 respectively, so that is how the sequential numbers are generated on this sheet. Again, hyphens are used to show where the formula is active but not returning anything, rather than using "" which is difficult to see !! The second formula finds the row where that sequential number exists in column U of that sheet.

    So, in column A an INDEX formula retrieves data from column A of the appropriate sheet for the matching record, with this formula in A7:

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    A similar formula with b:b, c:c instead of a:a could be used to get data from column B, column C etc. However, I did notice that you have some gaps in your data on some of the sheets, so rather than return a zero for these (which is Excel's default approach), I modified the formula in column C to this:

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    i.e. if it is empty then return a blank otherwise return the value. This is then copied across with changes made to the c:c to suit other columns. And with the appropriate formatting set for dates etc., that is basically it. The set-up for the OverdueDocs sheet is very similar, although the formulae in the helper columns look at column V in the other sheets.

    Well I hope this explains how the sheet works and that you can use it going-forward.

    I'll submit the post first and then attach the file, as the Forum is acting up a bit today and I don't want to lose it all as happened to me the other day.

    Pete
    Last edited by Pete_UK; 03-07-2013 at 08:45 PM.

  15. #15
    Registered User
    Join Date
    03-06-2013
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    31

    Re: VBA to 'on open' of workbook look at all sheets for 'OVERDUE' and transfer to Main Rep

    And you my 'unrequested friend' were wondering why I had such confidence in your abilities!! I'm doing an 'It works, it works it works" dance. Amazing! Thank you so so much!

  16. #16
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,724

    Re: VBA to 'on open' of workbook look at all sheets for 'OVERDUE' and transfer to Main Rep

    You're welcome, Pip - thanks for feeding back. Glad to hear that it works for you.

    Pete

+ Reply to Thread

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