+ Reply to Thread
Results 1 to 16 of 16

Match Date rows from separate workbooks

  1. #1
    Forum Contributor
    Join Date
    05-27-2012
    Location
    New Brunswick, Canada
    MS-Off Ver
    Excel 2016
    Posts
    327

    Match Date rows from separate workbooks

    I have the following code that matches a date in cell A1 from ThisWorkbook (Book1 - which I called Calc) with dates in Row 1 of Book2 (which I called Why) and pastes B8:B9 accordingly.

    What I'd like to do is expand it so it matches dates in Row 1 of both workbooks, copies Rows 8-9 from Book2 accordingly and pastes into Rows 2-3 of Book1. Ideally then create a loop so it goes through Sheet 1 to 7 of Book2. The date it would match would still be in A1 since I don't want it matching ALL the dates - otherwise it would populate an entire year's worth of data from 7 different sheets. I only need 4 dates at a time so I'll just retype what's in A1 and run the macro 4 times.

    Book1 is attached with the results I'd like to have pulled from Book2.

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by Wheelie686; 09-11-2021 at 11:19 PM.

  2. #2
    Valued Forum Contributor
    Join Date
    11-04-2018
    Location
    Denpasar
    MS-Off Ver
    Excel 2010
    Posts
    777

    Re: Match Date rows from separate workbooks

    The code below need both workbooks are open
    Please Login or Register  to view this content.
    The process :
    the code need the user to type the date in dd-mmm-yy format.
    then the code find what column is the date (inputted by the user) in row1 of wb-1 sheet1 then keep it in a variable cl
    then it put the date on cell A1 of wb-1 sheet1

    loop to each sheet in wb-2
    where on each sheet of wb-2 it also find what column is the date (inputted by the user),
    get the value of row 7 and row 8 of the found column
    then put the value to the corresponding row and column on wb-1 sheet1.

    I hope I understand what you want for the expected result.

    I only need 4 dates at a time so I'll just retype what's in A1 and run the macro 4 times.
    if the 4 dates are in consecutive date,
    for example the inputted date is 12-sep-21, and you want to get the value of 12-sep-21 to 15-sep-21,
    I think you can modify the vl variable and also modify the range of wb-1 sheet1 to be fill with the vl value,
    so you don't have to type the date 4 times and run the macro after each typing.
    Last edited by karmapala; 09-12-2021 at 09:17 AM.

  3. #3
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,523

    Re: Match Date rows from separate workbooks

    Wheelie686,

    Again, you don't need to open Book2.xlsb.
    Assuming both workbooks are in the same folder.
    Please Login or Register  to view this content.

  4. #4
    Forum Contributor
    Join Date
    05-27-2012
    Location
    New Brunswick, Canada
    MS-Off Ver
    Excel 2016
    Posts
    327

    Re: Match Date rows from separate workbooks

    Jindon,
    I renamed my workbooks just to make it a little simpler for me.
    Cap – Row 1 formatted as Custom with every 7th day beginning on June 28, 2020. This is how the document I’ll be pulling from is formatted so I made my mock up document to match.
    Why – Row 1 formatted as Date with every day from Nov 1, 2020 to Feb 13, 2022.
    I realize the dates from both workbooks don’t start/end on the same dates nor are they formatted the same way. I can update the way Row 1 on Why is formatted but not Cap if that could be the reason it’s not working properly.
    After some testing, even on a brand-new Why workbook, it seems to be pasting in Column T even when T1 had no date in it when I use Nov 1, 2020 as my input box date.
    So it seems to be pasting the right info but pasting in the columns that matched the source workbook, which is Cap. I know this because Nov 1, 2020 in Cap is in Column T but in Why, it’s Column B.
    Attached Files Attached Files

  5. #5
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,523

    Re: Match Date rows from separate workbooks

    Then you also need to find the columns of matched date in why workbook.
    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    05-27-2012
    Location
    New Brunswick, Canada
    MS-Off Ver
    Excel 2016
    Posts
    327

    Re: Match Date rows from separate workbooks

    A few more changes that I made to Cap to make it look like the workbook I'll eventually want to implement it into - again I'm using more of a mockup so I don't share sensitive info. It's a very big workbook so I didn't want to go into it and delete 15 pages of sensitive data.
    So your latest code works but I only if I leave the sheets named default (Sheet1, Sheet2, etc etc). I thought I'd rename sheets 9 to 15 to match the "real" document but then the code no longer worked, with the following line highlighted.
    Please Login or Register  to view this content.
    So I changed this line
    Please Login or Register  to view this content.
    to (having renamed Sheet9 to Bob)
    Please Login or Register  to view this content.
    I thought that would do the trick but I still get "Runtime Error 1004. Application defined or object defined error".
    I assume there's something else in the the code I need to change?
    Last edited by Wheelie686; 09-15-2021 at 10:41 PM.

  7. #7
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,523

    Re: Match Date rows from separate workbooks

    What else did you change?

  8. #8
    Forum Contributor
    Join Date
    05-27-2012
    Location
    New Brunswick, Canada
    MS-Off Ver
    Excel 2016
    Posts
    327

    Re: Match Date rows from separate workbooks

    Here is the updated documents. Nothing about Why changed.
    Attached Files Attached Files

  9. #9
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,523

    Re: Match Date rows from separate workbooks

    You need to change it like this.
    Please Login or Register  to view this content.

  10. #10
    Forum Contributor
    Join Date
    05-27-2012
    Location
    New Brunswick, Canada
    MS-Off Ver
    Excel 2016
    Posts
    327

    Re: Match Date rows from separate workbooks

    I'm not sure I understand why it matters that Sheet 10 to 15 have to stay the same. I understand it's hard coded with the first sheet name Bob but is there a way to reference the index and not the name?
    Not trying to make this difficult, I thought that only Sheet 9 was the sheet that had to reference the name but changing any of them messes it all up?

  11. #11
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,523

    Re: Match Date rows from separate workbooks

    Please Login or Register  to view this content.
    Last edited by jindon; 09-16-2021 at 04:50 AM.

  12. #12
    Forum Contributor
    Join Date
    05-27-2012
    Location
    New Brunswick, Canada
    MS-Off Ver
    Excel 2016
    Posts
    327

    Re: Match Date rows from separate workbooks

    So after much messing around with the file that I can't share, I've found that the sheet index is ALL messed up so what looked like sheet 9 to 15 was actually a bunch of random sheets anywhere from 18 to 35! So I think it's best to go back to the drawing board.

    So my GetHC sub pulls the data I need into CapV2, then I just need to match the dates from CapV2 with the dates in Why.
    I bolded the part that I am very sure is wrong but I can't seem to get the right syntax to get it right so I left it as is and hope that you'd help out one more time.

    Please Login or Register  to view this content.
    Attached Files Attached Files

  13. #13
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,523

    Re: Match Date rows from separate workbooks

    Quote Originally Posted by Wheelie686 View Post
    and hope that you'd help out one more time.
    No more help to the one who doesn't say appreciation.

  14. #14
    Forum Contributor
    Join Date
    05-27-2012
    Location
    New Brunswick, Canada
    MS-Off Ver
    Excel 2016
    Posts
    327

    Re: Match Date rows from separate workbooks

    I'm sorry if I've come off as unappreciative. You've helped on all my posts recently and I am extremely thankful for all the help you've provided.

  15. #15
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,523

    Re: Match Date rows from separate workbooks

    Please Login or Register  to view this content.

  16. #16
    Forum Contributor
    Join Date
    05-27-2012
    Location
    New Brunswick, Canada
    MS-Off Ver
    Excel 2016
    Posts
    327

    Re: Match Date rows from separate workbooks

    Thank you so much jindon! I was finally able to complete my project due to your help. Much appreciated!

+ 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. Creating a macro to split data into separate workbooks and separate worksheets
    By jfish07 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-27-2019, 10:48 AM
  2. Check to see if all values in row match any rows in a separate range
    By Groovicles in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-29-2018, 10:07 AM
  3. Replies: 7
    Last Post: 08-09-2016, 09:09 AM
  4. adding and deleting rows and separate workbooks
    By studiopear in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 07-22-2015, 11:35 AM
  5. Pulling Date from separate sheets using INDEX and MATCH
    By mlbdc2012 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-05-2015, 09:49 AM
  6. Date Match between WorkBooks
    By Dreamwine59 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-28-2007, 12:12 PM
  7. Match amounts from 2 separate workbooks
    By carlav60 in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 01-08-2007, 03:03 PM

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