Hyperlink from one sheet to another in same spreadsheet

Posted on 2012-08-20
Last Modified: 2012-08-21
Need some help with some Excel VBA for an Excel 2007 spreadsheet.

Have a spreadsheet where I've got a worksheet named Suppliers (data is dynamic and is populated from an SQL Server database, and can have up to around 30,000 entries), so will have entries such as

         A                      B
    SupplierName     SupplierNo
1   SUPPLIER-1           001
2   SUPPLIER-2           002
3   SUPPLIER-3           003

The spreadsheet would also have another worksheet named SupplierDetails.

What I'd like to be able to do is this. The SupplierDetails worksheet would be initially hidden. The user should be able to click on any SupplierNo (so each SupplierNo should be a hyperlink), at which point the SupplierDetails worksheet should become visible.

Once SupplierDetails is visible, the user should then be taken to SupplierDetails worksheet. At that point, I will populate the SupplierDetails worksheet with various details from the SQL Server database, but I need to be able to pick up the the value of the SupplierNo which the user clicked back on the Suppliers worksheet.

I've got all the plumbing in place for populating the worksheets from the database, but just need to know specifically how to

      a) Initially have the SupplierDetails worksheet hidden;
      b) Have each SupplierNo on the Suppliers worksheet as a hyperlink
      c) As the user clicks on the SupplierNo hyperlink, the SupplierDetails worksheet
         should then become visible, and the user should be taken to cell A1 on
         the SupplierDetails worksheet, with that cell containing the specific  
                   SupplierNo which the user clicked back on the SupplierDetails worksheet.
      d) I can then pick up this SupplierNo on the SupplierDetails worksheet and
         pass that value down as a parameter to my database stored proc.
Would really appreciate some help in Excel VBA with points a-c ....         


Question by:raymurphy
    LVL 13

    Expert Comment

    To toggle visibility.  Sheets("SupplierDetails").Visible = false
    I wouldn't use "hyperlink". If you want to format it in blue and underline, ok, but just handle the click event.

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.Range.Cells.Count = 1 And Target.Column = 1 Then
        Sheets("SuppliersDetail").Visible = True
    End If
    End Sub

    Open in new window


    Author Comment

    Thanks for the prompt reply   ..  I'm fairly new to Excel VBA, so excuse my dumb questions.

    So would the code Worksheet_SelectionChange go against my Suppliers worksheet, and is that the only code I would need under  Worksheet_SelectionChange ? Also still not sure how this code would pick up the SupplierNo that has been clicked on the first Suppliers worksheet ....
    LVL 13

    Accepted Solution

    The event is in the Suppliers Wks, yes.  It is fired everytime you move/click to a new cell, so the first if statement restricts it to just 1 cell, and it has to be in column 1 (Col A).

    You would need another function that does whatever query for the given supplierNo, which would be available as Target.Text  since target is the cell you clicked on, which is the supplier  no in this case.

    Author Comment

    Thanks for this - my initial tests seem OK ...

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Sometimes we don't want to show zeros in our Excel spreadsheets. This is sometimes most evident in our charts. Look at the chart below, all the zero values are visible. I think that all will agree with the fact that zero values are not looking nice …
    A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
    This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
    This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now