+ Reply to Thread
Results 1 to 31 of 31

Show values of selected table row in other cell

  1. #1
    Registered User
    Join Date
    01-29-2013
    Location
    The Netherlands
    MS-Off Ver
    2016 x64
    Posts
    48

    Question Show values of selected table row in other cell

    Hi all,

    Attached a sample file of the table.

    when the user selects a certain cell within the table (table name: "Table1") then I want to have the values of the cells in column D and E (of the selected row) shown in D1 and E1.

    So the value of D1 and E1 constantly changes depending on the row that is selected. It should not matter which cell is selected. E.g. when A10 is selected, then D10 and E10 should be used.

    I am thinking of using something like the "intersect" function. However, I do not really know how this works in vba and IF it will work.

    Next step is that I use that value to run a Filter macro from the Ribbon. But first I need to get the correct values ;-)
    This should run on Excel 2010, 2013 and 2016.

    Thanks,
    Daniel
    Attached Files Attached Files

  2. #2
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Show values of selected table row in other cell

    Hi,

    You can add this code to the worksheet code module
    Please Login or Register  to view this content.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

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

    Re: Show values of selected table row in other cell

    Try this...Put code in sheet module
    Please Login or Register  to view this content.
    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!!!

  4. #4
    Valued Forum Contributor
    Join Date
    03-16-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    371

    Re: Show values of selected table row in other cell

    Here's my take on this. A more general approach using your named ranges and easier to change names etc. if they change in the future. You only want the top yellow cells to populate if you have only one row selected in the table; else blank (or change to whatever you want).

    In a normal module (I don't like having big chunks of code behind worksheets as I forget about them):
    Please Login or Register  to view this content.
    In the worksheet code behind Sheet1:
    Please Login or Register  to view this content.
    Design everything to be as simple as possible, but no simpler.

  5. #5
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Show values of selected table row in other cell

    very similar to xlnitwit

    sheet module:
    Please Login or Register  to view this content.
    Click *Add Reputation to thank those who helped you. Ask if anything is not clear

  6. #6
    Valued Forum Contributor
    Join Date
    03-16-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    371

    Re: Show values of selected table row in other cell

    Everyone else's code will break if any new columns are inserted on the left hand side or if the yellowed cells are moved or not next to each other. Mine doesn't... just saying

  7. #7
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Show values of selected table row in other cell

    @stormin' - yours will break if the named range is deleted or the table is renamed

  8. #8
    Valued Forum Contributor
    Join Date
    03-16-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    371

    Re: Show values of selected table row in other cell

    In balance of probability... it is more likely for an end user that is not involved in the design to insert a column, move some cells, or even add a new table (so cannot rely on ListObjects(1)) than to rename the main table or delete/rename named ranges.
    Constants are up the top for easy changing for the developer (and no counting of columns required)

  9. #9
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Show values of selected table row in other cell

    @stormin'
    What's probability (or logic) got to do with likely user behaviour?
    And it does not matter how easy it is for the developer to fix the code (especially if he's at home for Christmas)
    - if the named range is deleted then your code is still just as broken as everyone else's!

  10. #10
    Valued Forum Contributor
    Join Date
    03-16-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    371

    Re: Show values of selected table row in other cell

    Likewise, if the workbook is deleted everyone's code is broken

  11. #11
    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,351

    Re: Show values of selected table row in other cell

    Can't this all be dealt with using some sheet protection???
    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.

  12. #12
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Show values of selected table row in other cell

    Merry Xmas @AliGW

    @stormin' - I still have no idea where you are going with your "asides". What's the "punchline"?

  13. #13
    Valued Forum Contributor
    Join Date
    03-16-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    371

    Re: Show values of selected table row in other cell

    There is no punchline, I was just expanding on your logic to expose the fragility of it.
    I have a feeling that we are overthinking the issue way beyond the OP's original question

  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,351

    Re: Show values of selected table row in other cell

    OK, chaps - no more bickering, please. Let's not let this get out of hand. If you have nothing to add that does not go some way towards solving the weaknesses in each of your solutions, please don't post. Thanks!

  15. #15
    Registered User
    Join Date
    01-29-2013
    Location
    The Netherlands
    MS-Off Ver
    2016 x64
    Posts
    48

    Re: Show values of selected table row in other cell

    hi all, thank you for the many responses
    For your info; I have protected the worksheets. Users can add lines, but not add/delete columns. And also, users cannot delete or create tables.
    I want to use this logic on mulitple worksheets with tables with different names ( the 2 essential columns have the same name in all tables).

  16. #16
    Valued Forum Contributor
    Join Date
    03-16-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    371

    Re: Show values of selected table row in other cell

    - Same code to work across multiple worksheets in the same workbook
    - Only one table per worksheet
    - Each table has a different table name
    - Target columns have the same heading in each table
    - Yellowed cells are in the same position in each workshet and will not be moved

    Some minor modifications (in red) to the code above for those criteria. I've forgone the use of the defined names you set on your yellowed cells to allow it to work on more than one sheet.

    Please Login or Register  to view this content.
    Then for each worksheet that you require this function, just put the following into the code behind the worksheet:
    Please Login or Register  to view this content.

  17. #17
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Show values of selected table row in other cell

    @stormin' - how ironic!

  18. #18
    Valued Forum Contributor
    Join Date
    03-16-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    371

    Re: Show values of selected table row in other cell

    @kev_ I know, right! I thought of you when writing that post haha

  19. #19
    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,351

    Re: Show values of selected table row in other cell

    Nice to see we now have a bromance - much nicer.

  20. #20
    Registered User
    Join Date
    01-29-2013
    Location
    The Netherlands
    MS-Off Ver
    2016 x64
    Posts
    48

    Re: Show values of selected table row in other cell

    Hi Stormin',
    I tried your code and it works beautifully

    Now I want to make it a little bit more complex. I have a workbook with multiple worksheets and multiple lists.
    Eventually I want to call a "filter macro" from the ribbon that uses the result of the intersect code you provided.

    How can I make this code work on all the lists I have in the workbook. It is fair to assume that each list will have the same 2 columns (budget task and worksheet).

    So basically the name of the worksheet and list is different each worksheet. To make it a bit easier for me with the filter macro, I put the intersect outcome on a separate worksheet. So the intersect result of each list should go to the same cells in the "config" worksheet.

    I attached an example file to demonstrate.
    Attached Files Attached Files

  21. #21
    Valued Forum Contributor
    Join Date
    03-16-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    371

    Re: Show values of selected table row in other cell

    Sorry Dan, I'm not sure I understand exactly what you mean.
    Will your filter macro filter all the tables with the same two criteria in the config sheet?
    Which table's intersect goes into the cells in the config sheet?

  22. #22
    Registered User
    Join Date
    01-29-2013
    Location
    The Netherlands
    MS-Off Ver
    2016 x64
    Posts
    48

    Re: Show values of selected table row in other cell

    The filter macro in the Ribbon will only run on the active sheet.
    So I want to run one single macro from the ribbon that works on all worksheets (with a list that has meets the criteria of these 2 columns). So each time you determine the intersect in a list it will put the result in that Config worksheet. That way the macro only needs to check that worksheet for the filter criteria.
    I probably also need to have the name of the active list put on that Config worksheet..?

    I hope this clarifies it a bit

  23. #23
    Valued Forum Contributor
    Join Date
    03-16-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    371

    Re: Show values of selected table row in other cell

    Ah, okay, so your macro will use only the activesheet's intersect to filter only the activesheet's table. Then of course you should be able to select any similar sheet and run the same macro to filter just that sheet's table with just that sheet's intersect.

    Is that correct? You won't need a config sheet for this, we can just read directly from the activesheet each time.

  24. #24
    Registered User
    Join Date
    01-29-2013
    Location
    The Netherlands
    MS-Off Ver
    2016 x64
    Posts
    48

    Re: Show values of selected table row in other cell

    Hi, sorry for the late response. I haven't had time to work on this for while. And now I do again :-)

    Yes, that is correct. I have multiple worksheets (approx +10) with a table in it . The TableName is different for each sheet of course.
    If I can store the output values on the filter (Budget Task and WorkStream) in a variable I can use in a macro that is run from the Ribbon, then that is good for me too. (maybe even better)

    So I would need to determine the activesheet and the activetable to make it dynamic.

    With the current logic it stops in debug mode and the line with "Set oTbl = .ListObjects(sTblName)"
    This makes sense as a few lines above we have defined "Const sTblName As String = "Table1" and this should be made dynamic. Is there a function for ActiveTable? Or do we need more to make this work?

  25. #25
    Valued Forum Contributor
    Join Date
    03-16-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    371

    Re: Show values of selected table row in other cell

    Yep change that to
    Please Login or Register  to view this content.
    to grab the 'first' listobject on that sheet, which should be that table.

    Let me know if it works as you want it to.

  26. #26
    Registered User
    Join Date
    01-29-2013
    Location
    The Netherlands
    MS-Off Ver
    2016 x64
    Posts
    48

    Thumbs up Re: Show values of selected table row in other cell

    Yes! Briliant
    This solved it for me.

    Thanks a lot!

  27. #27
    Valued Forum Contributor
    Join Date
    03-16-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    371

    Re: Show values of selected table row in other cell

    Just make sure that that section looks like this:
    Please Login or Register  to view this content.
    Glad it's working, happy to help

  28. #28
    Registered User
    Join Date
    01-29-2013
    Location
    The Netherlands
    MS-Off Ver
    2016 x64
    Posts
    48

    Re: Show values of selected table row in other cell

    Hi, sorry to reopen this thread. I now see that the "Work Stream" column does exist in every table, however not always in the same place.
    Is there a way to first determine the location of both columns before applying he filter?

    Daniel

  29. #29
    Valued Forum Contributor
    Join Date
    03-16-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    371

    Re: Show values of selected table row in other cell

    As long as the columns are named exactly the same, it will find them regardless of the position in the table.

  30. #30
    Registered User
    Join Date
    01-29-2013
    Location
    The Netherlands
    MS-Off Ver
    2016 x64
    Posts
    48

    Re: Show values of selected table row in other cell

    They are named exactly the same. However I do get empty filtered table when column is at different position...

    Please Login or Register  to view this content.
    When the Budget Task is not the 4th column, but the 6th (or any other number), the filter still filters on the value found for "Budget Task" and applies that filter on Field4 (which holds other data)

  31. #31
    Valued Forum Contributor
    Join Date
    03-16-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    371

    Re: Show values of selected table row in other cell

    Sorry I thought you were talking about my code. That's something different.

    One method to find the table field number by field header is using the MATCH worksheet function:
    Please Login or Register  to view this content.
    Last edited by Stormin'; 01-31-2018 at 11:25 AM.

+ 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. Replies: 11
    Last Post: 04-29-2017, 07:23 PM
  2. click to show text in cell, retract when cell not selected
    By LMoir in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-23-2016, 05:57 AM
  3. Show help message depending on selected cell
    By bubusi in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-18-2015, 03:21 AM
  4. Replies: 2
    Last Post: 01-30-2013, 03:16 AM
  5. Show comments next to selected cell
    By Marco-Kun in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-16-2009, 07:17 AM
  6. Show Calendar When Cell is Selected
    By siamadu in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 02-26-2009, 02:12 PM
  7. [SOLVED] Is there a formula to show which cell is currently selected
    By Chris in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 05-08-2006, 10:40 AM

Tags for this Thread

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