+ Reply to Thread
Results 1 to 6 of 6

Select entire row based on data validation selection

  1. #1
    Registered User
    Join Date
    12-17-2012
    Location
    Poland
    MS-Off Ver
    2013
    Posts
    57

    Select entire row based on data validation selection

    Hi guys,

    I have a simple table with distances between Italian cities. dist.xlsx

    What I'm trying to have is when a user chooses a starting point (A14 - validated list), cell B14 will show a destination location that is the closest to the selection in A14, based on the data from the table.

    Now I thought that I could simply use the MIN formula to check which value in a row is the lowest, then copy the heading (B2:H2) of that value into B14. But how to tell VBA to select the entire row in which the starting city is located in the first place? So, say a user chooses the city Inveruno in A14. Then after hitting the macro button, cell B14 would output the city Arluno, which is at 10 km from Inveruno.

    I'm not new to VBA (let's say pre-intermidiary), but I just can't seem to figure this out...
    Last edited by mintymike; 08-01-2013 at 03:04 AM.

  2. #2
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Select entire row based on data validation selection

    Hi mintymike

    This Code is in the attached and appears to do as you require. Please note, in the event of ties it picks the first.
    Please Login or Register  to view this content.
    Attached Files Attached Files
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  3. #3
    Registered User
    Join Date
    12-17-2012
    Location
    Poland
    MS-Off Ver
    2013
    Posts
    57

    Re: Select entire row based on data validation selection

    Hi John,

    wow, that's awesome!! It does exactly what I wanted!! Not sure if I can ask about one more thing in this thread or should I start a new one, but... Using the excel above and your code, is there a way of adding another header in C13, called something like Nearest destination 2 and have the code input in C14 a city name that would be second closest? I know this might be complicated, so let me give an example.

    I can't reuse your code for cell C14, because if the code finds the closest location, and if we choose ie. Arluno, your code will show in B14 Inveruno as the closest - and it is correct. But then if we wanted to use the code again in C14, it would again show Arluno - because it is the closest one to Inveruno. And I'd like to choose Arluno and have the VBA show me: B14 - Inveruno, C14 - Gaggiano (because this one is the closest to Inveruno, not counting Arluno).

    If I should start a new thread and mark this one as SOLVED, just let me know and I'll do so. Thanks for the commitment so far.
    Last edited by mintymike; 07-29-2013 at 03:43 AM.

  4. #4
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Select entire row based on data validation selection

    Hi mintymike

    Could have swore I posted this the other day...ah well
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    12-17-2012
    Location
    Poland
    MS-Off Ver
    2013
    Posts
    57

    Re: Select entire row based on data validation selection

    Thank you very much, you've saved me a great deal of time. Marking this as SOLVED.

  6. #6
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Select entire row based on data validation selection

    You're welcome...glad I could help. Thanks for the Rep.

+ 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. Pull Data from Multiple Columns Based On Data Validation List Selection
    By CHRISOK in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-13-2013, 11:41 PM
  2. [SOLVED] Formula Based on Multi-Level Data Validation Selection
    By warrior2411 in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 02-07-2013, 08:34 PM
  3. Cut and Paste Entire Row Based on Selection is Hanging when Selection is Not Found
    By therealrichie in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-26-2012, 06:00 PM
  4. Need macro which locks cells (C57:C61) based on data validation selection (C1)
    By mopetten in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-06-2012, 04:17 PM
  5. Replies: 2
    Last Post: 05-02-2012, 07:31 AM

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