+ Reply to Thread
Results 1 to 23 of 23

If value is Y, return values in range and copy to another sheet.

  1. #1
    Registered User
    Join Date
    07-27-2022
    Location
    Cumbria, UK
    MS-Off Ver
    365
    Posts
    17

    Post If value is Y, return values in range and copy to another sheet.

    I have a database of information, which I would like to use to populate the values in other sheets if it matches a given criteria.

    My issue is, values in column G can change from No to Yes.

    If value in column G = Yes, I then need it to copy the associated values from columns B:C into A:B columns in the EQA sheet. The EQA sheet also contains additional details that are not found in the Database.

    Values in column G may change, therefore changes need to update automatically in the EQA page.

    I tried =FILTER but this didn't move/allow for the additional information in columns C:J within the EQA sheet.

    Can anyone suggest a solution?

    I am currently having to manually enter details from one sheet to another which is really time consuming, especially as I need to replicate this scenario within other sheets for other criteria.
    Attached Files Attached Files
    Last edited by SF_2011_uk; 07-27-2022 at 10:02 AM.

  2. #2
    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
    80,783

    Re: If value is Y, return values in range and copy to another sheet.

    Welcome to the forum.

    Please update your forum profile with the version of Excel that this neesd to work with - is that 365?

    If so, then this will do what youy want:

    =FILTER(Database!B2:C10,Database!G2:G10="Yes")

    However, the remaining columns in the EQA table will NOT be dynamic if you fill them manually.

    You need to explain how this is meant to work in context.
    Last edited by AliGW; 07-27-2022 at 09:57 AM.
    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.

  3. #3
    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: If value is Y, return values in range and copy to another sheet.

    Are you intending to add the extra information to the EQA sheet manually? The drawback with doing that is that you would normally have the extracted data in the same sequence as it appears in the Database sheet, but if one of those records were to have a change in the value in column G (from yes to no, or vice-versa) then the sequence would change as there would be one fewer or one more record. Any manually-entered data would thus not align with the correct record.

    Hope this helps.

    Pete

  4. #4
    Registered User
    Join Date
    07-27-2022
    Location
    Cumbria, UK
    MS-Off Ver
    365
    Posts
    17

    Re: If value is Y, return values in range and copy to another sheet.

    Hello

    Thank you for the replies. Yes the additional information in the EQA sheet would be manually entered.

    I have tried the =FILTER, but when a record in the database, column G is changed to Yes it doesn't allow for the change in the EQA sheet and the data is no longer aligned.

    Is there a solution?

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

    Re: If value is Y, return values in range and copy to another sheet.

    This is what we were both saying.

    The solution is to enter ALL data on the source sheet, then filter it.

  6. #6
    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
    80,783

    Re: If value is Y, return values in range and copy to another sheet.

    Duplicate threads are NOT allowed. You must continue here, but if you want, I can move this thread to the VBA section for you. Do you want this?

  7. #7
    Registered User
    Join Date
    07-27-2022
    Location
    Cumbria, UK
    MS-Off Ver
    365
    Posts
    17

    Re: If value is Y, return values in range and copy to another sheet.

    Thanks, but unfortunately that is not an option as the source sheet already has 38 columns.

    I also need to apply a solution to several other sheets which need to link back to the source sheet. Each sheet contains manually entered data specific to the records within that sheet.

    It wouldn't be possible to have everything on one sheet.

    Thanks anyway

  8. #8
    Registered User
    Join Date
    07-27-2022
    Location
    Cumbria, UK
    MS-Off Ver
    365
    Posts
    17

    Re: If value is Y, return values in range and copy to another sheet.

    oops sorry, yes please.

    as a formula isn't possible I'm wondering if a vba may work

  9. #9
    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
    80,783

    Re: If value is Y, return values in range and copy to another sheet.

    It would have to be VBA for the reasons we've stated. Moving the thread now.

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

    Re: If value is Y, return values in range and copy to another sheet.

    Try this;
    Please Login or Register  to view this content.
    Run the macro 'InitialLoad' to load up sheet EQA with those that are already "Yes"
    The other routine will handle those that change from No to Yes
    Last edited by Croweater; 07-28-2022 at 06:21 PM.

  11. #11
    Registered User
    Join Date
    07-27-2022
    Location
    Cumbria, UK
    MS-Off Ver
    365
    Posts
    17

    Re: If value is Y, return values in range and copy to another sheet.

    Hi

    Thanks for that, however it still hasn't sorted my problem.

    It has selected the records which contain yes in column g, however following any changes in column g and the macro is re-run,
    rather than just adding the new/updated records it will re-add all the existing records that were copied previously. I have reattached my example including the VBA.

    It there any way that it can remove any duplicates? Therefore each time the macro is run it will only add new records?
    Attached Files Attached Files

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

    Re: If value is Y, return values in range and copy to another sheet.

    1. Start with a Blank EQA Sheet. (Columns A and B Blank at least.)

    2. Copy the code I gave you into the Database sheet. It is important you get the right sheet. (Right click on the sheet tab>View Code>Paste it in there).

    3. There are TWO macros in that code. One you will see from your macros tool, the other will execute when you change form NO to YES.

    4. Run the InitialLoad macro ONCE. (That is why I called it INITIAL Load. If all the ones with Yes by their name are ALREADY on the EQA sheet, you don't need to run this at all).

    5. When you change from NO to YES the OTHER macro will run automatically and add the NEW name.

    6. Don't run the InitialLoad macro EVER AGAIN. (Delete it if you like.).

    PS. You didn't include the code with your attached example, so I can't see what sheet you put it in. It has to go in the Database sheet, because that is the sheet you will be making changes on that require certain action to take place.
    Last edited by Croweater; 07-30-2022 at 07:53 PM.

  13. #13
    Registered User
    Join Date
    07-27-2022
    Location
    Cumbria, UK
    MS-Off Ver
    365
    Posts
    17

    Re: If value is Y, return values in range and copy to another sheet.

    Thank you so much for this. It works perfectly!

  14. #14
    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
    80,783

    Re: If value is Y, return values in range and copy to another sheet.

    If that takes care of your original question, please choose Thread Tools from the menu link above and mark this thread as SOLVED.

    Also, if you have not already done so, you may not be aware that you can thank those who have helped you by clicking the small star icon (* Add Reputation) located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of all those who offered help.

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

    Re: If value is Y, return values in range and copy to another sheet.

    Quote Originally Posted by SF_2011_uk View Post
    Thank you so much for this. It works perfectly!
    You're very welcome.

  16. #16
    Registered User
    Join Date
    07-27-2022
    Location
    Cumbria, UK
    MS-Off Ver
    365
    Posts
    17

    Re: If value is Y, return values in range and copy to another sheet.

    Hi Croweater

    Sorry, having trouble entering the code into my real spreadsheet.

    I have edited the code to pick up the initial "Yes" responses but when a NO to YES change is made it isn't copying the update details into the EQA sheet.

    What am I doing wrong?

    TIA

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

    Re: If value is Y, return values in range and copy to another sheet.

    1. When you "edited the code", what changes did you make?
    2. Did you put it in the correct sheet (ie. the Database sheet), where the change is being made?
    3. In your "real spreadsheet", is the No to Yes change still being made in column G?
    4. The code works with "Yes" (exactly that). Are you entering "YES"?

    If you want it to work with Yes,YES,yes,yEs or any other combination, a slight change will need to be made to the code. Also make sure there are no trailing spaces.

    This minor mod will take care of just about all of those issues with your input (if that is what you want). Change that one line to this;
    Please Login or Register  to view this content.
    They're the only things I can think of as to why it would not work. You may need to put an extract of the real sheet up, so that I can look at it for you.
    Last edited by Croweater; 08-02-2022 at 08:06 PM.

  18. #18
    Registered User
    Join Date
    07-27-2022
    Location
    Cumbria, UK
    MS-Off Ver
    365
    Posts
    17

    Re: If value is Y, return values in range and copy to another sheet.

    Hi Croweater,

    Thanks, tried that but still not working.

    I've attached my real spreadsheet, with some dummy data and the VBA code that I modified.

    Please can you check and advise what's gone wrong?
    Attached Files Attached Files

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

    Re: If value is Y, return values in range and copy to another sheet.

    OK There are a few issues here.

    1. The YES/NO you have mentioned before is in column K which is dependent on column M which is in turn dependent on columns N O and P (which are not determined by a formula). The only column out of those which is NOT hidden is column N.

    The Worksheet Change event is triggered by a manual change to the worksheet so you have to decide what (manual) change triggers your 'event'. As the others are hidden, I am guessing the change the user makes is in Column N?
    However the worksheet change is checking for a change in column K, so it does nothing. You need to decide which column the user is going to change and check for that column or columns, instead of column K

    2. Your dropdown in column N is uppercase but the code checks only for a mix of upper and lower, so you need to make the change I suggested in post #17. Note that we are now talking column N NOT K. If you really need to check the value in column K, we MAY need to change your value check from Target to Range("K" & Target.Row) or maybe something else depending on how you are going to use this sheet. (See point 4).


    3. You are putting the surname in twice, so you need to change that too. (A simple typo when you modified the code I gave you)

    4. This all depends on actually how you are going to use this workbook. If you are going to unhide columns and change them, you may end up with the situation where a name is added twice (or not added at all) because row K is already Yes and is still Yes (or we are not checking for a change to hidden columns).
    IF that is the case you will need more checking to determine if the change you made actually CHANGED column K, but I will not complicate things if it's not needed. That will be up to you to determine how you use this.
    Last edited by Croweater; 08-03-2022 at 08:44 PM.

  20. #20
    Registered User
    Join Date
    07-27-2022
    Location
    Cumbria, UK
    MS-Off Ver
    365
    Posts
    17

    Re: If value is Y, return values in range and copy to another sheet.

    Hi

    In the spreadsheet there are 12 sheets which are updated manually.

    Two of these sheets have a column that will update with a TRUE value if the formula conditions are met (New Starter = column V and Company Dr =
    column P. Using any TRUE values in those columns, there are formulas in the Database sheet in column O:P which will also return a TRUE value.
    Based on the values in O:P, the K column will then return YES or NO. Column N is a manual entry and is there incase a NO to YES change needs
    to be made that doesn't come from the New Starter or Company Dr Sheet.

    The trigger change needs to be when the Database column K changes from NO to YES, but the change won't be manual it will be the result of a formula
    if the conditions are met.

    In terms of using the workbook - The white columns are for manually entering values, the pale grey will populate based on formulas and will be seen
    by the user, but the dark grey columns will be hidden from view of the user.

    I have attached the full spreadsheet again showing all the sheets within the workbook. I have added some dummy data, run the VBA code, then made a
    manual change to "Jane Jones" record in the 'Company Dr' sheet. This then returned the TRUE value in column P in the 'Database' sheet, which returned YES in column K.
    However, the NO to Yes change didn't then copy the data to the 'EQUAL' sheet.

    You mentioned in the previous post that I am putting the surname in twice? Which section do you mean?

    llrow = Worksheets("EQUAL").Range("H" & Rows.Count).End(xlUp).Row + 1
    Worksheets("EQUAL").Range("H" & llrow) = Range("I" & Target.Row)
    Worksheets("EQUAL").Range("I" & llrow) = Range("I" & Target.Row)

    I think I need to do a lot of reading up on VBA codes. Completely new to this side if Excel.

    If we can solve this issue, I would like to apply a VBA to the 'New Starter' sheets, which if columns Z:AJ return a TRUE value, it would copy the
    names from H:I into columns H:I within the specified sheet.

    For example;

    if 'New Starter' column Z is TRUE, copy H:I to 'Audiometry' sheet; column H:I

    and so on for the other sheets.

    TIA
    Attached Files Attached Files

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

    Re: If value is Y, return values in range and copy to another sheet.

    Quote Originally Posted by SF_2011_uk View Post
    Hi

    However, the NO to Yes change didn't then copy the data to the 'EQUAL' sheet.
    I explained why this happened, it is because you didn't MANUALLY change column K, which is what that macro checks for

    Quote Originally Posted by SF_2011_uk View Post
    You mentioned in the previous post that I am putting the surname in twice? Which section do you mean?

    llrow = Worksheets("EQUAL").Range("H" & Rows.Count).End(xlUp).Row + 1
    Worksheets("EQUAL").Range("H" & llrow) = Range("I" & Target.Row)
    Worksheets("EQUAL").Range("I" & llrow) = Range("I" & Target.Row)
    Yes, that section. Look at it. You are are setting both cells in the EQUAL sheet to the same thing, Range("I" & Target.Row), which is the surname.

    Quote Originally Posted by SF_2011_uk View Post
    I think I need to do a lot of reading up on VBA codes. Completely new to this side if Excel.
    Yes. Good idea. I also think it's a good idea to keep your workbook as simple as you can to make it easier to change. (See my post below)
    Last edited by Croweater; 08-04-2022 at 10:07 PM.

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

    Re: If value is Y, return values in range and copy to another sheet.

    OK I've changed my mind on how to do this. There are too many sheets, too many ways (with formula and within different sheets) which can update the column you are looking at and too many columns with critical values with columns of (almost) zero width (why?) etc. etc.

    The real-world example is so different to your sample workbook, I have given up on trying to get this update done effectively in real time.

    This macro should do what you want. Run it every time you want to add names to the EQUAL sheet.

    It goes in the OH Database sheet.

    Please Login or Register  to view this content.
    Last edited by Croweater; 08-04-2022 at 10:08 PM.

  23. #23
    Registered User
    Join Date
    07-27-2022
    Location
    Cumbria, UK
    MS-Off Ver
    365
    Posts
    17

    Re: If value is Y, return values in range and copy to another sheet.

    Hi

    Thanks for the reply. Not ideal to have to run the code each time, but better than nothing.

    Thanks again for your help.

+ 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] Copy range values from several rows to another sheet
    By saravnepali in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-01-2020, 05:04 PM
  2. [SOLVED] Vba copy range from sheet 1 and paste values within a range on sheet 2
    By A440 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-27-2017, 10:23 AM
  3. Copy Range Name Values from Each Sheet to Summary Sheet
    By Branbran10 in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 04-09-2015, 05:53 PM
  4. [SOLVED] Copy Range values only from sheet 1 to sheet 2
    By compgeek1979 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-27-2015, 01:16 PM
  5. [SOLVED] Copy and paste range as values to specific sheet/range
    By lukestkd in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-06-2014, 09:48 PM
  6. Replies: 1
    Last Post: 11-02-2012, 08:32 AM
  7. Replies: 3
    Last Post: 04-10-2012, 01:51 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