+ Reply to Thread
Results 1 to 3 of 3

Hyperlink cells to cetrain sheets with macro

Hybrid View

  1. #1
    Registered User
    Join Date
    03-25-2009
    Location
    Sweden
    MS-Off Ver
    Excel 2003
    Posts
    49

    Hyperlink cells to cetrain sheets with macro

    Hey,

    I have a big workbook that runs alot of scripts etc so to make my life easier i have a compilation with all the sheetnames (and the data on the sheets in a more simple way) in my workbook,

    Now i was planning that instead of scrolling through 100's on sheets to find the specific one i wanted to do a vba that made my compilation into hyperlinks to the right sheet.

    Im sending a small xls file to show what i mean.

    in "sheet2" i have a button, and when i click on it i want all the numbers in my "A column" to get linked to the right sheet (that ofcourse is already created).

    for example in the dile im sending i have 5 sheets, "standard" "sheet2", "1111", "2222", "3333"

    In my "a Column" in "sheet2" i have the numbers 1111,2222,3333.

    And what i want is that when i click my button all the numbers get hyperlinked so that after the hyperlink is made, i can click on 1111 on "sheet2" and then i will be directed to the "1111" sheet.

    I have been trying another method with this using below code but it dosent cut it real (there is some unessecery code for what i want to accomplish but its made in my real sheet where more stuff is made)

    Sub Link_To_New_Worksheet() 
        Dim wbBook As Workbook 
        Dim wsSheet As Worksheet, wsInvisible As Worksheet, wsLinkFrom As Worksheet 
        Dim rnActive As Range 
        Dim strName As String 
         
        Set wbBook = ActiveWorkbook 
         
        With wbBook 
            Set wsInvisible = .Worksheets("Test") 
            Set wsLinkFrom = .Worksheets("TOC") 
        End With 
         
        If ActiveSheet.Name <> wsLinkFrom.Name Then 
            MsgBox "The TOC must be active!", vbCritical 
            Exit Sub 
        End If 
         
        With wsLinkFrom 
            Set rnActive = ActiveCell 
        End With 
         
        If rnActive.Value <> "" Then 
            strName = rnActive.Value 
        Else 
            MsgBox "No value was found in the active cell!", vbCritical 
            Exit Sub 
        End If 
         
        Application.ScreenUpdating = False 
         
        With wsInvisible 
            .Visible = xlSheetVisible 
            .Copy After:=wbBook.Worksheets(wbBook.Worksheets.Count) 
        End With 
         
        Set wsSheet = ActiveSheet 
         
        With wsSheet 
            .Name = strName 
            wsLinkFrom.Hyperlinks.Add rnActive, "", _ 
            SubAddress:="'" & .Name & "'!A2", _ 
            TextToDisplay:=.Name 
        End With 
         
        wsInvisible.Visible = xlSheetHidden 
         
        Application.ScreenUpdating = True 
         
    End Sub

    Next step that i wanna do is copy/move the information in the new active sheet (like in my example above the "1111" sheet to the "standard" sheet. This is the next step tho and i havent put any time figure that one ouot yet myself tho.

    Any help or hints are appriciated
    Attached Files Attached Files
    Last edited by Zheno; 10-27-2011 at 02:23 AM.

  2. #2
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: Hyperlink cells to cetrain sheets with macro

    This is the code you can use to hyperlink your sheets. Just assign the macro to your button.

    Sub create_links()
    
    lrow = Worksheets("Sheet2").Range("A2").End(xlDown).Row
    
    For i = 2 To lrow
    
        Range("A" & i).Hyperlinks.Add anchor:=Range("A" & i), Address:="", SubAddress:="'" & Range("A" & i).Value & "'!A1"
        
    Next
    
    End Sub

  3. #3
    Registered User
    Join Date
    03-25-2009
    Location
    Sweden
    MS-Off Ver
    Excel 2003
    Posts
    49

    Re: Hyperlink cells to cetrain sheets with macro

    Thanks arlu1201,

    It work perfect for the problem i described,

    After i implented this i noticed tho that with the hyperlinks i get a new problem with my next step in the macro, so i think i have to go on another route iif i cant figure out how to do what i want.

    I think i have to go on a event with selction change.

    Once again thanks for the help and im most liikely have to make a new post.

+ 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