+ Reply to Thread
Results 1 to 39 of 39

How to fetch data from a sheet based on conditions?

  1. #1
    Forum Contributor
    Join Date
    01-01-2022
    Location
    India
    MS-Off Ver
    Home 2021
    Posts
    777

    How to fetch data from a sheet based on conditions?

    Hi all,

    Hope all are well.

    Need a help with a macro in attached sheet.

    1. Macro is to be run from sheet "Closed"

    2. The number in column A in sheet "Closed" needs to be searched under column A in sheet "Extract - Incidents" and based on this common number, the data in column column AC (Resolution Code) in sheet "Closed" is to be fetched from column M (Resolution code) in sheet "Extract - Incidents".

    3. Similarly data under column AD (Resolution Notes) in sheet "Closed" to be fetched from column N (Resolution notes) in sheet "Extract - Incidents".

    4. Both columns AC and AD to be auto filled up to last filled row.

    4. All data in sheet "Extract - Incidents" starting from row 4 to be deleted while retaining 3rd row.

    5. Then cursor to to be placed at cell O3 (First Closed) of sheet "Closed"

    Note:

    i. Fetched data to be pasted as values (not as formula)

    ii. Some numbers will not be found, so the result should be N/A. Expected results in file.

    iii. This is a daily activity where new data will be uploaded in the sheet "Extract - Incidents".

    Can someone help with the solution please?
    Attached Files Attached Files
    Last edited by rizwanulhasan; 04-16-2024 at 09:13 AM.

  2. #2
    Forum Contributor
    Join Date
    01-01-2022
    Location
    India
    MS-Off Ver
    Home 2021
    Posts
    777

    Re: How to fetch data from a sheet based on conditions?

    Modified requirement in post # 1. Table in sheet "Extract - Incidents" converted to range.

  3. #3
    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,228

    Re: How to fetch data from a sheet based on conditions?

    Password???

    All data in sheet starting from row 4 to be deleted while retaining 3rd row.
    Which sheet?
    Last edited by JohnTopley; 04-16-2024 at 08:05 AM.
    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

  4. #4
    Forum Contributor
    Join Date
    01-01-2022
    Location
    India
    MS-Off Ver
    Home 2021
    Posts
    777

    Re: How to fetch data from a sheet based on conditions?

    Hi John,

    Thanks for your response.

    File unprotected and reattached in post #1.

    All data in sheet "Extract - Incidents" starting from row 4 to be deleted while retaining 3rd row.

    Sorry for the trouble.

  5. #5
    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,228

    Re: How to fetch data from a sheet based on conditions?

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by JohnTopley; 04-16-2024 at 10:42 AM.

  6. #6
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,248

    Re: How to fetch data from a sheet based on conditions?

    Please Login or Register  to view this content.
    Last edited by sintek; 04-16-2024 at 09:53 AM.
    Good Luck
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the star to left of post [Add Reputation]
    Also....add a comment if you like!!!!
    And remember...Mark Thread as Solved.
    Excel Forum Rocks!!!

  7. #7
    Forum Contributor
    Join Date
    01-01-2022
    Location
    India
    MS-Off Ver
    Home 2021
    Posts
    777

    Re: How to fetch data from a sheet based on conditions?

    @JohnTopley @sintek

    Thanks a bunch. Its working perfectly.

  8. #8
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,248

    Re: How to fetch data from a sheet based on conditions?

    Glad to have contributed...Tx for rep +

  9. #9
    Forum Contributor
    Join Date
    01-01-2022
    Location
    India
    MS-Off Ver
    Home 2021
    Posts
    777

    Re: How to fetch data from a sheet based on conditions?

    Hi again,

    Just a small help.

    I want to add one more condition in below code.

    Please Login or Register  to view this content.
    The number in column A in sheet "Closed" needs to be searched under column A in sheet "Extract - Incidents" and based on this common number, the data in column column N (Updated) in sheet "Closed" is to be fetched from column J (Resolved) in sheet "Extract - Incidents". However, this search should be only for the values which has "Incident" under column B (Task type) in sheet "Closed". For others, values in column N should remain as it is. Finally, column N to be auto filled up to last filled row.

    Can someone please help
    Last edited by rizwanulhasan; 04-24-2024 at 07:53 AM.

  10. #10
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,248

    Re: How to fetch data from a sheet based on conditions?

    want to add one more condition
    Please Login or Register  to view this content.
    Last edited by sintek; 04-24-2024 at 09:26 AM.

  11. #11
    Forum Contributor
    Join Date
    01-01-2022
    Location
    India
    MS-Off Ver
    Home 2021
    Posts
    777

    Re: How to fetch data from a sheet based on conditions?

    Hi Sintek,

    Thanks for your response.

    1 issue faced.

    If the value under column B is not "Incident", then column N is being populated as 00-Jan-1900 00:00:00, whereas it should retain original value, as mentioned in previous post.

    Also, i forgot to mention that if an incident i snot found in sheet "Extract - Incidents", then result should be N/A. Sorry for the miss.

  12. #12
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,248

    Re: How to fetch data from a sheet based on conditions?

    See amended above...
    Last edited by sintek; 04-24-2024 at 09:25 AM.

  13. #13
    Forum Contributor
    Join Date
    01-01-2022
    Location
    India
    MS-Off Ver
    Home 2021
    Posts
    777

    Re: How to fetch data from a sheet based on conditions?

    Attached
    Attached Files Attached Files
    Last edited by rizwanulhasan; 04-24-2024 at 09:38 AM.

  14. #14
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,248

    Re: How to fetch data from a sheet based on conditions?

    What happens if it finds the number that has Incident task but the date in Col J in Extract sheet is empty...
    Why is this date empty anyway...?

  15. #15
    Forum Contributor
    Join Date
    01-01-2022
    Location
    India
    MS-Off Ver
    Home 2021
    Posts
    777

    Re: How to fetch data from a sheet based on conditions?

    Good question

    In that case, the value can be blank. The date is empty because the incident is not yet resolved. Only if column G in sheet "Closed" is either Resolved or Closed, then date under column J in sheet "Extract - Incidents" will be populated, else will be empty.

  16. #16
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,248

    Re: How to fetch data from a sheet based on conditions?

    Geez...And the plot thickens...Don't have time right now...Need to rush off...Will check in later tonight...

  17. #17
    Forum Contributor
    Join Date
    01-01-2022
    Location
    India
    MS-Off Ver
    Home 2021
    Posts
    777

    Re: How to fetch data from a sheet based on conditions?

    No worries, take your time

  18. #18
    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,228

    Re: How to fetch data from a sheet based on conditions?

    Late to the party ...

    Please Login or Register  to view this content.

  19. #19
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,248

    Re: How to fetch data from a sheet based on conditions?

    As your dataset is probably large...Looping data in array and then writing back to sheet,will be faster than formula and evaluate function...
    This incorporates initial and additional requirement...
    Please Login or Register  to view this content.
    Last edited by sintek; 04-24-2024 at 03:35 PM.

  20. #20
    Valued Forum Contributor
    Join Date
    11-28-2015
    Location
    indo
    MS-Off Ver
    2016 64 bitt
    Posts
    1,304

    Re: How to fetch data from a sheet based on conditions?

    Perhab
    Please Login or Register  to view this content.

  21. #21
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,248

    Re: How to fetch data from a sheet based on conditions?

    Just for closure...Evaluate incorporating all requirements...
    Please Login or Register  to view this content.

  22. #22
    Forum Contributor
    Join Date
    01-01-2022
    Location
    India
    MS-Off Ver
    Home 2021
    Posts
    777

    Re: How to fetch data from a sheet based on conditions?

    Quote Originally Posted by sintek View Post
    Just for closure...Evaluate incorporating all requirements...
    Please Login or Register  to view this content.
    Hi sintek,

    Some of the values in column AD are not being fetched "Extract - Incidents" sheet

  23. #23
    Forum Contributor
    Join Date
    01-01-2022
    Location
    India
    MS-Off Ver
    Home 2021
    Posts
    777

    Re: How to fetch data from a sheet based on conditions?

    Hi @John and @Daboho,

    Thanks for the response.

    The macro in post 18 and 20 works however in a sheet with 1400 rows, it took 10 minutes for the macro to run and eventually excel hung up
    Last edited by rizwanulhasan; 04-25-2024 at 08:10 AM.

  24. #24
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,248

    Re: How to fetch data from a sheet based on conditions?

    Some of the values in column AD are not being fetched "Extract - Incidents" sheet
    Works for me as it should for me...See attached...

    Post 19 also works as it should...And will be faster than 18 & 20
    Attached Files Attached Files
    Last edited by sintek; 04-25-2024 at 08:27 AM.

  25. #25
    Forum Contributor
    Join Date
    01-01-2022
    Location
    India
    MS-Off Ver
    Home 2021
    Posts
    777

    Re: How to fetch data from a sheet based on conditions?

    Strange. AC and AD are not being fetched properly in attached file.

    Post 19 is perfect but slower than code in post 21
    Attached Files Attached Files

  26. #26
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,248

    Re: How to fetch data from a sheet based on conditions?

    Your sheet is filtered...

  27. #27
    Forum Contributor
    Join Date
    01-01-2022
    Location
    India
    MS-Off Ver
    Home 2021
    Posts
    777

    Re: How to fetch data from a sheet based on conditions?

    i tried even without the sheet filtered, yet fields missing

  28. #28
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,248

    Re: How to fetch data from a sheet based on conditions?

    yet fields missing
    Please upload a small sample showing which fields are missing...All works with your original sample file...

  29. #29
    Forum Contributor
    Join Date
    01-01-2022
    Location
    India
    MS-Off Ver
    Home 2021
    Posts
    777

    Re: How to fetch data from a sheet based on conditions?

    Attached and highlighted in yellow
    Attached Files Attached Files

  30. #30
    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,228

    Re: How to fetch data from a sheet based on conditions?

    Please Login or Register  to view this content.
    Schoolboy error!

  31. #31
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,248

    Re: How to fetch data from a sheet based on conditions?

    Attached and highlighted in yellow
    Oh okay, now I get it...There is a character limit that vlookup can handle...Your info exceeds this limit...255...reduce it and you will see all works as it should...

    OR revert to Post 19...
    OR index Match...
    Last edited by sintek; 04-25-2024 at 10:23 AM.

  32. #32
    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,228

    Re: How to fetch data from a sheet based on conditions?

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

  33. #33
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,248

    Re: How to fetch data from a sheet based on conditions?

    This will be faster than Post 19...
    Please Login or Register  to view this content.
    Last edited by sintek; 04-26-2024 at 03:00 AM.

  34. #34
    Valued Forum Contributor
    Join Date
    11-28-2015
    Location
    indo
    MS-Off Ver
    2016 64 bitt
    Posts
    1,304

    Re: How to fetch data from a sheet based on conditions?

    Perhab
    Please Login or Register  to view this content.

  35. #35
    Forum Contributor
    Join Date
    01-01-2022
    Location
    India
    MS-Off Ver
    Home 2021
    Posts
    777

    Re: How to fetch data from a sheet based on conditions?

    @John,

    Post # 32 is faster and perfect.

    @sintek

    All good with post # 33 except that dates appear in 20-12-2023 01:07:01 PM instead of 20-Dec-2023 01:07:01 PM and sheet "Extract - Incident" doesn't clear.

    @daboho

    Getting "Compile error: Variable not defined"

    Thanks a bunch to everyone for the prompt response
    Last edited by rizwanulhasan; 04-26-2024 at 12:37 AM.

  36. #36
    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,228

    Re: How to fetch data from a sheet based on conditions?

    Thank you for the rep.

    And well done on your reply where you addressed each respondent individually: a model others should follow

  37. #37
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    81,073

    Re: How to fetch data from a sheet based on conditions?

    Absolutely, John - the epitome of completeness and fairness.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  38. #38
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,248

    Re: How to fetch data from a sheet based on conditions?

    All good with post # 33 except that dates appear in 20-12-2023 01:07:01 PM instead of 20-Dec-2023 01:07:01 PM
    slight snippet addition...
    Please Login or Register  to view this content.
    sheet "Extract - Incident" doesn't clear.
    That snippet was cmmented out for testing...
    Please Login or Register  to view this content.
    Glad you got it sorted though and so many options...Tx for rep +
    Please Login or Register  to view this content.
    Last edited by sintek; 04-26-2024 at 03:06 AM.

  39. #39
    Forum Contributor
    Join Date
    01-01-2022
    Location
    India
    MS-Off Ver
    Home 2021
    Posts
    777

    Re: How to fetch data from a sheet based on conditions?

    @sintek

    Thanks again.

    @John @ AliGW

    Thanks both. Will follow it always

+ 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] How to fetch data from other sheets in one sheet based on quarters?
    By rizwanulhasan in forum Excel Formulas & Functions
    Replies: 19
    Last Post: 10-09-2023, 03:03 AM
  2. To fetch data from sheet 2 based on the selections made on sheet 1
    By maryflower in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-24-2017, 03:22 PM
  3. Need help to fetch data from other sheet based on Resource Name
    By Sanjibghosh in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 12-26-2016, 04:22 AM
  4. Data Fetch From One Sheet to Another Sheet Based on Check Box
    By Sanjibghosh in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-02-2016, 10:56 AM
  5. Fetch the data from another sheet based on drop down list
    By sreejeshc in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-25-2015, 02:26 AM
  6. Excel 2007 : How do I fetch data based on conditions
    By fabtshow in forum Excel General
    Replies: 6
    Last Post: 06-03-2012, 07:48 PM
  7. Fetch data from another sheet based on a filter value
    By jrule in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-30-2011, 12:38 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