+ Reply to Thread
Results 1 to 11 of 11

Extract reference numbers in given month with date?

  1. #1
    Forum Contributor
    Join Date
    10-11-2012
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    358

    Extract reference numbers in given month with date?

    Hoping someone can help me with this one. I have attached an example spreadsheet which should be relatively intuitive over me trying to explain it.

    I am wanting to extract all CJ numbers with the corresponding dates from Sheet 1, into Sheet 2. It has to factor in, engineer name (as stated on sheet 2), the Month (as stated in sheet 2 "May") with the "Attended site" date in sheet 1....

    If you see the worksheet it should give you the whole picture with a fair amount of clarity

    Thanks very much for your help in advance!!
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor
    Join Date
    09-01-2013
    Location
    Dallas, TX
    MS-Off Ver
    Excel 2010
    Posts
    324

    Re: Extract reference numbers in given month with date?

    Hello,

    Under what condition should everything be transferred or should everything be transferred over? and how do you want it initiated, based on a date you iput or...? Need just a little more specifics.


    Shelton A.
    If Helpful, Add Reputaion!

  3. #3
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,882

    Re: Extract reference numbers in given month with date?

    If you change the value in Sheet 2, C3 to a numerical value, ie. For May, change to 5, then the following VBA will work for you. The value in C3 must be the number of the month
    Please Login or Register  to view this content.
    How to install your new code
    1. Copy the Excel VBA code
    2. Select the workbook in which you want to store the Excel VBA code
    3. Press Alt+F11 to open the Visual Basic Editor
    4. Choose Insert > Module
    5. Edit > Paste the macro into the module that appeared
    6. Close the VBEditor
    7. Save your workbook (Excel 2007+ select a macro-enabled file format, like *.xlsm)

    To run the Excel VBA code:
    1. Press Alt-F8 to open the macro list
    2. Select a macro in the list
    3. Click the Run button
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Extract reference numbers in given month with date?

    Here's a non-vba solution using array formulas:

    B5: =IFERROR(INDEX(Sheet1!$C$1:$C$34, SMALL(IF((Sheet1!$B$1:$B$34=$B$2)*(TEXT(Sheet1!$C$1:$C$34, "MMMM")=$C$3)*(Sheet1!$J$1:$J$34="Yes"), ROW(Sheet1!$B$1:$B$34), ""), ROW(A1))), "")

    C5: =IFERROR(INDEX(Sheet1!$G$1:$G$34, SMALL(IF((Sheet1!$B$1:$B$34=$B$2)*(TEXT(Sheet1!$C$1:$C$34, "MMMM")=$C$3)*(Sheet1!$J$1:$J$34="Yes"), ROW(Sheet1!$B$1:$B$34), ""), ROW(A1))), "")

    ...confirmed by pressing CTRL+SHIFT+ENTER to activate the array, not just ENTER. You will know the array is active when you see curly braces { } appear around your formula. If you do not CTRL+SHIFT+ENTER you will get an error or a clearly incorrect answer. Press F2 on that cell and try again.

    Once the B5 and C5 answers appear correctly, copy those two cells down the table.
    Attached Files Attached Files
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  5. #5
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Extract reference numbers in given month with date?

    Alan, a tweak to your macro that would allow him to still put "May" or "September" in C3:

    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    10-11-2012
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    358

    Re: Extract reference numbers in given month with date?

    Quote Originally Posted by JBeaucaire View Post
    Here's a non-vba solution using array formulas:

    B5: =IFERROR(INDEX(Sheet1!$C$1:$C$34, SMALL(IF((Sheet1!$B$1:$B$34=$B$2)*(TEXT(Sheet1!$C$1:$C$34, "MMMM")=$C$3)*(Sheet1!$J$1:$J$34="Yes"), ROW(Sheet1!$B$1:$B$34), ""), ROW(A1))), "")

    C5: =IFERROR(INDEX(Sheet1!$G$1:$G$34, SMALL(IF((Sheet1!$B$1:$B$34=$B$2)*(TEXT(Sheet1!$C$1:$C$34, "MMMM")=$C$3)*(Sheet1!$J$1:$J$34="Yes"), ROW(Sheet1!$B$1:$B$34), ""), ROW(A1))), "")

    ...confirmed by pressing CTRL+SHIFT+ENTER to activate the array, not just ENTER. You will know the array is active when you see curly braces { } appear around your formula. If you do not CTRL+SHIFT+ENTER you will get an error or a clearly incorrect answer. Press F2 on that cell and try again.

    Once the B5 and C5 answers appear correctly, copy those two cells down the table.

    Thanks for everyones input. I've dug into this one to start off with.

    Actualy formula I am using is this one:

    Please Login or Register  to view this content.
    Problem is though, it's just returning a "0" now and again? Cannot figure out why that is?

    As for the date, I am not as fussed about the specific dates for time being. The "CJ" number is the important part, but it's not pulling it properly?

    Am I doing something wrong in that formula?

  7. #7
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Extract reference numbers in given month with date?

    If your formula is bringing back even one correct value, then it's probably the correct formula and the reason for 0 is that the same formula is resolving to a row with no value due to an error in your data. To suggest what that error might be I'd have to see it happening.

  8. #8
    Forum Contributor
    Join Date
    10-11-2012
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    358

    Re: Extract reference numbers in given month with date?

    I've actually sorted it now. I think I was applying your formula incorrectly! Thank you kindly, and everyone else for their solutions!

    Appreciate it

  9. #9
    Forum Contributor
    Join Date
    10-11-2012
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    358

    Re: Extract reference numbers in given month with date?

    Quote Originally Posted by JBeaucaire View Post
    If your formula is bringing back even one correct value, then it's probably the correct formula and the reason for 0 is that the same formula is resolving to a row with no value due to an error in your data. To suggest what that error might be I'd have to see it happening.
    Could you elaborate on this? I am actually experiencing this issue after expanding on your original formula with this:

    =IFERROR(INDEX('Overview - 2014'!$G$15:$G$5000, SMALL(IF(('Overview - 2014'!$B$15:$B$5000=$B$3)*(('Overview - 2014'!$C$15:$C$5000>=DATE(2014,4,28))*('Overview - 2014'!$C$15:$C$5000<=DATE(2014,5,27)))*('Overview - 2014'!$J$15:$J$5000="Yes"),ROW('Overview - 2014'!$B$15:$B$5000), ""), ROW(A1))), "")

    I know it's tough to make out by glancing at it like this, but I have literally checked over my data points several times and cannot for the life of me see where I am going wrong...

    So if it's returning "0" it definitely means that there is something wrong with the formatting of the data? Either way, when i FIRST put this into the relevant box and SHIFT+CTRL enter, it will always produce the right answer in that box, then when I try to simply drag it down it will produce a "0" if there is an applicable answer, however, it should be "CJxxxxx" (example).

    Any ideas?

  10. #10
    Forum Contributor
    Join Date
    10-11-2012
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    358

    Re: Extract reference numbers in given month with date?

    Any suggestions?

  11. #11
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Extract reference numbers in given month with date?

    In my original formulas, I explicitly start the search range at row1 in each "range" of cells in the formula due to the fact the MATCH function in the formula doesn't need to be adjusted when you do that. Since your new version of the formula starts all the ranges at row15, then the MATCH function would need to be adjusted by 14 so the results now work in the INDEXed range.

    Simplest answer, change all the 15 references to 1 and see if that resolves the issue.

    Less simple to my mind, but still works, adjust the ROW() reference by 14 to match the INDEXed range:

    =IFERROR(INDEX('Overview - 2014'!$G$15:$G$5000, SMALL(IF(('Overview - 2014'!$B$15:$B$5000=$B$3)*(('Overview - 2014'!$C$15:$C$5000>=DATE(2014,4,28))*('Overview - 2014'!$C$15:$C$5000<=DATE(2014,5,27)))*('Overview - 2014'!$J$15:$J$5000="Yes"),ROW('Overview - 2014'!$B$15:$B$5000)-14, ""), ROW(A1))), "")

  12. #12
    Forum Contributor
    Join Date
    10-11-2012
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    358

    Re: Extract reference numbers in given month with date?

    Amazing - spot on! I think I understand.

    Really appreciate your expertise!

+ 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. Extract Day from Date returning Month instead of Day
    By Epscan in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 03-06-2013, 01:51 AM
  2. Extract part of date, depending on day of the month
    By gogty in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-31-2013, 12:33 PM
  3. Extract birthday date and month
    By grey_hair in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 02-02-2011, 12:09 PM
  4. Extract Month from date IE 3/10/2010 = 3
    By randell.graybill in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-12-2010, 12:30 AM
  5. extract the month of a date
    By gireesh in forum Excel General
    Replies: 11
    Last Post: 11-23-2005, 02:10 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