+ Reply to Thread
Results 1 to 9 of 9

Creating hyperlinks from Data Validation list to other sheets within xls

  1. #1
    Registered User
    Join Date
    03-22-2010
    Location
    London
    MS-Off Ver
    2007
    Posts
    49

    Unhappy Creating hyperlinks from Data Validation list to other sheets within xls

    Hi all

    I was hoping someone might be able to help me with some VBA code.

    I have 5 cells which are linked to a Data Validation list, and the excel spreadsheet users are encouraged to select 5 options from this drop-down.

    Ideally, once they have selected their option, it should link to the corresponding sheet in the workbook when it is next clicked... Is this possible using VBA code?

    Intuitively, I think I may need to do it some other way because I would suppose that if the VBA code can overwrite the cell and change it to a hyperlink, it effectively overwrites the Data Validation in that cell?

    I have attached a dummy workbook (which currently has no code) which I hope better explains what I mean.

    I was thinking code like the following might be applicable, but I can't currently make it work. There is no error message, it just doesn't change the text in the cell to a hyperlink:


    Please Login or Register  to view this content.

    (I've copied the code above from the extensive code on my original worksheet and just adapted to illustrate for the Dummy Worksheet example.)

    I've read a bit about using combo boxes, but I am not an excel season pro, and not sure if they would be helpful in this context...

    Any help greatly appreciated, and many thanks in advance!

    Best

    Diane
    Attached Files Attached Files
    Last edited by dpcp; 02-29-2012 at 12:51 PM.

  2. #2
    Valued Forum Contributor smuzoen's Avatar
    Join Date
    10-28-2011
    Location
    Brisbane, Australia
    MS-Off Ver
    Excel 2003/2007/2010
    Posts
    610

    Re: Creating hyperlinks from Data Validation list to other sheets within xls

    On the Main Sheet worksheet place a worksheet change event
    Please Login or Register  to view this content.
    This is for the drop down in B6 (do you need the other drop down boxes?) This way you do not need to create hyperlinks - the other way is to use a workbook open event to iterate through all the worksheets and place hyperlinks on the front page. So In ThisWorkbook add
    Please Login or Register  to view this content.
    So if sheets get added then this hyperlink list is created fresh every time workbook is opened
    Last edited by smuzoen; 02-28-2012 at 08:42 AM.
    Hope this helps.
    Anthony
    Pack my box with five dozen liquor jugs
    PS: Remember to mark your questions as Solved once you are satisfied. Please rate the answer(s) by selecting the Star in the lower left next to the Triangle. It is appreciated?

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

    Re: Creating hyperlinks from Data Validation list to other sheets within xls

    IF you use VBA to add a hardcode hyperlink to a cell with DV in it, it would not remove the DV. But it isn't really necessary. You could just use the "adjacent" cell to display a "Link" using the HYPERLINK formula for the same functionality and no VBA.


    If the DV is in cell A1, then in B1 could be this formula:

    =IF(A1="", "", HYPERLINK('" & A1 & "'!A1", "Link"))
    _________________
    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!)

  4. #4
    Registered User
    Join Date
    03-22-2010
    Location
    London
    MS-Off Ver
    2007
    Posts
    49

    Re: Creating hyperlinks from Data Validation list to other sheets within xls

    Thank you both for your reply.

    smuzoen -
    I tried both the codes you provided and a couple of issues:
    - the first code would work, but in my actual workbook, the sheet names do not exactly match the drop down lists. I've illustrated this in the attached dummy worksheet.
    - I would apply the code from B6:B9

    With the second code, I've tried to adapt that to my actual workbook, but I'm afraid I do not understand all the coding...In my actual workbook I will have up to 40 values in my Data Validation, and all 40 of those will link to a separate worksheet - but the user will only ever choose a maximum of 5 from the 40.

    I think the code above would work if I had named the sheets as the values in the Data Validation...

    JBeaucaire -
    I understand what you mean about using the adjacent cell to display the hyperlink, but my actual worksheet has a lot of formatting and the adjacent cells have other purposes.

    If there are any other suggestions you have then I'd greatly appreciate them, but in the meantime I will also tinker around as I have done previously, and perhaps stumble upon another solution!

    Many thanks again.

    Best

    Diane
    Attached Files Attached Files

  5. #5
    Valued Forum Contributor smuzoen's Avatar
    Join Date
    10-28-2011
    Location
    Brisbane, Australia
    MS-Off Ver
    Excel 2003/2007/2010
    Posts
    610

    Re: Creating hyperlinks from Data Validation list to other sheets within xls

    You could still use a worksheet change event. I did notice that the drop down for example was Sheet 1, Sheet 2 (spaces in between Sheet and number) whereas excel has Sheet1, Sheet2 etc. That is why I used
    Please Login or Register  to view this content.
    This removed the space from the name in the drop down list. However depending on what the names are you could use something like
    Please Login or Register  to view this content.
    Use the select case command - Make the Case is = to the name in the drop down list. Then place the actual sheet name in the Worksheets("Name of sheet") command. If you are going to have 4 drop down lists then just change the Range("B6") to the cell with the drop down list and adjust the select case command. Hope that makes sense.

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

    Re: Creating hyperlinks from Data Validation list to other sheets within xls

    I still think it's remarkably simple to add a column next to your drop downs to get the HYPERLINK() function slipped in there.

    Meanwhile, your drop downs must relate to actual sheets in SOME way. If you've created a drop down list you could put the Sheets they link to in the next column to create a table. I added the sheet names on yuor sheet, then selected both sets of values and named that range of cells MyList.

    Then a worksheet_change macro can be employed to create real hardcoded hyperlinks in the DV cells themselves.

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

  7. #7
    Registered User
    Join Date
    03-22-2010
    Location
    London
    MS-Off Ver
    2007
    Posts
    49

    Re: Creating hyperlinks from Data Validation list to other sheets within xls

    Thank you both for your responses!

    smuzoen - I have tried your code and that does work, however, it takes the user to the new worksheet as soon as the selection is made...ideally, the navigation to the new worksheet shouldn't happen simultaneously as the selection, but rather once the user clicks on the cell again.

    JBeaucaire - I see how the code works in the dummy worksheet you've attached, but I can't seem to adapt it for what I'm working on. A few issues:

    1. Due to other bits of code, the list of hyperlinks that will be in the worksheet will be dynamic...so the MyList range should ideally collect

    Please Login or Register  to view this content.
    2. The user will not be able to define the MyList range, so is it possible to build this into the Private Sub?

    3. V4 and W4 will need to remain blank (in case the user does not wish to select any further options)

    Finally, my intention is to hide columns V and W, would this have an impact on the worksheet_change macro?

    I have attached another dummy with cells/names corresponding to what my actual workbook looks like. Here, I have named V4:W8 as "MyList"... but it would be helpful to have that range naming set up as part of the code (using Selection.End(xlDown))

    I really appreciate both your help, thanks very much .

    Best

    Diane
    Attached Files Attached Files

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

    Re: Creating hyperlinks from Data Validation list to other sheets within xls

    1) The MyList range can create itself, but never with a "select" approach. Humans do that, VBA doesn't need to. I would keep this out of VBA still, let the worksheet do it with a dynamic formula.

    Changing the NAME definition of MyList to a dynamic formula will allow it expand on its own to include any additional values you add to the V:W column:

    =OFFSET('Role Profile'!$V$4,,,COUNTA('Role Profile'!$V:$V)+1, 2)

    BTW, yes, you can safely hide the column, you could also add a sheet to hold all this reference stuff, then simply hide the sheet.


    2) The Data Validation in D28:D32 can now use the dynamic name, too, by changing the DV formula to:

    =OFFSET(MyList,,,,1)


    3) Since you're now using 2-word sheetnames, a tweak to the hyperlink code:
    Please Login or Register  to view this content.

    4) Design tip: When resorting to Hyperlink navigation, it's usually expected that a "HOME" link will be present on all the other sheets. I added one to A1 of each sheet. It is also expected to be visible at all times, to I did a FREEZE PANES on row2 of all those sheets, too, so row1 is always visible.
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    03-22-2010
    Location
    London
    MS-Off Ver
    2007
    Posts
    49

    Re: Creating hyperlinks from Data Validation list to other sheets within xls

    JBeaucaire

    Thanks very much, all of the above worked perfectly

    Really appreciated!

    All the best

    Diane

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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