+ Reply to Thread
Results 1 to 17 of 17

VBA-Perform lookup for all rows in column if date selected?

  1. #1
    Registered User
    Join Date
    09-25-2022
    Location
    West Coast, USA
    MS-Off Ver
    365 - Version 2308
    Posts
    61

    Question VBA-Perform lookup for all rows in column if date selected?

    I am hoping to find a way to select a date at the top of a column and perform a look for all of the cells below it, and a different lookup for those one row to the right.

    I have copied a bunch of things found and then went through chatgpt but what I'm getting from it isn't working. I originally was going to do this with xlookups on all of the cells which I finally got working, but the data behind it is huge and the user wont need all of them.

    I've attached an example and the code I have is below. Also below are the formulas that work to pull the data in case that helps.


    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by Anita Knapp; 09-22-2023 at 08:48 PM.

  2. #2
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,606

    Re: VBA-Perform lookup for all rows in column if date selected?

    Several errors in the code:

    Ws as Worksheet NOT WORKBOOK

    Lookup1 and Lookup2 are not defined

    Named ranges "Day", "Time" and "Res" not in the workbook

    And why use text date comparisons rather than Excel dates which you have in row 3?

    Please tell use exactly what you require to return: and what is "large" volume - how many rows?
    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

  3. #3
    Registered User
    Join Date
    09-25-2022
    Location
    West Coast, USA
    MS-Off Ver
    365 - Version 2308
    Posts
    61

    Re: VBA-Perform lookup for all rows in column if date selected?

    Thank you so much for replying! I've been working on this for a couple weeks and it's driving me crazy. I've updated the code and file.

    I think I fixed the Lookup1 and Lookup2 definitions but I'm not sure if I have the coding for that correct. The goal is if the user selects F5-O5, then it starts working in cell F6, doing a look up of the value of E6 and date in F5.

    Res, Day, and time are columns H, I, J in the data tab.

    I have the dates repeated in 3 and 5 because I was having issues with the formulas if they didn't have the TEXT conversion. Are you saying that I can just have my formatted date and it will read it?

    Presently, the source files load with 70,000 rows and is filtered down to 22,000 rows in the data tab that is being used for this. This will double by the end of the year.

    Thank you for your looking and tips is greatly appreciated!

    Please Login or Register  to view this content.

  4. #4
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,606

    Re: VBA-Perform lookup for all rows in column if date selected?

    Please add some manually-calculated results to your workbook.

  5. #5
    Registered User
    Join Date
    09-25-2022
    Location
    West Coast, USA
    MS-Off Ver
    365 - Version 2308
    Posts
    61

    Re: VBA-Perform lookup for all rows in column if date selected?

    I've just updated it with what it would look like if 9/3 and 9/4 (J5-M5) were selected when the macro ran.

    Thanks!

    Quote Originally Posted by JohnTopley View Post
    Please add some manually-calculated results to your workbook.

  6. #6
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,606

    Re: VBA-Perform lookup for all rows in column if date selected?

    Please Login or Register  to view this content.
    The data in "Sep" is sorted by DATE (column G) which makes the processing much faster. No helper column required.

    Also assumes the list of personnel is in place (columns D:E in "Sep")

    I assume the file does represent your actual file.
    Attached Files Attached Files
    Last edited by JohnTopley; 09-22-2023 at 03:52 AM.

  7. #7
    Registered User
    Join Date
    09-25-2022
    Location
    West Coast, USA
    MS-Off Ver
    365 - Version 2308
    Posts
    61

    Re: VBA-Perform lookup for all rows in column if date selected?

    Thank you so much for doing this! When I copy this over I'm getting a mismatch at idy = Application.Match(a(r, 1), IDrng, 0) . I rearranged my data and month sheet to match columns and rows so the only thing different is the sheet name that I've changed. I know it's tough without seeing the workbook, but any ideas on what it could be?

  8. #8
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,606

    Re: VBA-Perform lookup for all rows in column if date selected?

    Please Login or Register  to view this content.
    either sheet is not "Sep" and/or data range has changed

    OR

    Please Login or Register  to view this content.
    value in a(r,1) is invalid and/or "r" is "wrong. and/or IDrng is "wrong"

    without your w/book it is guess work.

  9. #9
    Registered User
    Join Date
    09-25-2022
    Location
    West Coast, USA
    MS-Off Ver
    365 - Version 2308
    Posts
    61

    Re: VBA-Perform lookup for all rows in column if date selected?

    It sorts my data and activates my month tab before it errors so I think its looking at the correct sheets. I thought I could figure out the issue by crossing the data and month sheets for both, but the X1 month with my data sheet and my month sheet with the X1 data both give the same error.


    I know you put what these items are but I don't think I'm understanding a few of them. (Probably more than that but these are the ones that I'm hoping I can catch my error on)

    Does (R,1) represent the IDs in the first column of the data range?
    Is the sRow the row that the dates are on?
    Is the nRow getting the total number of rows to complete from the date column of the data sheet?

    Thank you!

  10. #10
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,606

    Re: VBA-Perform lookup for all rows in column if date selected?

    as the data is sorted, srow is the row for the first September date. Nrow is the number of September dates and a(R,1) is the data in column E, a(r,2) is column F etc where r=row number

    NOTE: the row numbers are relative to the start of the range (dRng) so E5 is row 1, E6 is row 2 etc

  11. #11
    Registered User
    Join Date
    09-25-2022
    Location
    West Coast, USA
    MS-Off Ver
    365 - Version 2308
    Posts
    61

    Re: VBA-Perform lookup for all rows in column if date selected?

    Ok, thanks! I'm going to keep at it until I figure out what I have wrong here.

    Thank you for taking the time to put this together, it's greatly appreciated!

  12. #12
    Registered User
    Join Date
    09-25-2022
    Location
    West Coast, USA
    MS-Off Ver
    365 - Version 2308
    Posts
    61

    Re: VBA-Perform lookup for all rows in column if date selected?

    I was thinking it might have been something I had set in my workbook so I've made a new test book. I'm getting the error in the same spot. I've attached the new book, are you able to see what I'm doing wrong?
    Attached Files Attached Files

  13. #13
    Spammer
    Join Date
    10-23-2012
    Location
    Adelaide, Australia
    MS-Off Ver
    Excel 2003, Office 365
    Posts
    1,237

    Re: VBA-Perform lookup for all rows in column if date selected?

    I don't normally jump in on solved threads (it isn't is it?) or when someone else has done all the hard work (so apologies to John).

    Your problem is that you are trying to match employee codes from one sheet in another and they don't exist where you are trying to get an exact match.

    You need to handle this error in what is an appropriate way for your application (goto 'next r' maybe?).

  14. #14
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,606

    Re: VBA-Perform lookup for all rows in column if date selected?

    Please Login or Register  to view this content.
    Updated with error handling: mea culpa!
    Attached Files Attached Files
    Last edited by JohnTopley; 09-23-2023 at 02:11 AM.

  15. #15
    Registered User
    Join Date
    09-25-2022
    Location
    West Coast, USA
    MS-Off Ver
    365 - Version 2308
    Posts
    61

    Re: VBA-Perform lookup for all rows in column if date selected?

    It works! This is awesome, thanks!. Is there a way for it to only error if the ID on the month sheet isn't found on the data sheet? I have hundreds of ID's but if not, it looks like On Error Resume Next will work.

  16. #16
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,606

    Re: VBA-Perform lookup for all rows in column if date selected?

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

  17. #17
    Registered User
    Join Date
    09-25-2022
    Location
    West Coast, USA
    MS-Off Ver
    365 - Version 2308
    Posts
    61

    Re: VBA-Perform lookup for all rows in column if date selected?

    This is perfect, thanks so much!

+ 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. [SOLVED] VBA to perform sum of column values if number of rows and columns are not constant
    By aman1234 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-17-2015, 09:40 AM
  2. Replies: 12
    Last Post: 08-12-2014, 02:49 PM
  3. [SOLVED] Perform calculations for multiple rows based on specific column text
    By justinmirsky in forum Excel Programming / VBA / Macros
    Replies: 19
    Last Post: 03-31-2013, 08:20 PM
  4. Perform a two column lookup that returns a value from another column?
    By okstate1 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-02-2010, 07:13 PM
  5. Replies: 4
    Last Post: 01-17-2008, 06:05 PM
  6. Replies: 2
    Last Post: 08-02-2006, 04:40 PM
  7. [SOLVED] How do you perform a two-column lookup?
    By Kymm in forum Excel General
    Replies: 5
    Last Post: 10-20-2005, 01:05 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