1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Excel Macro Frustration, I think I'm missing something simple!

Discussion in 'Business Applications' started by Claireyscott, Jul 31, 2008.

Thread Status:
Not open for further replies.
  1. Claireyscott

    Claireyscott Thread Starter

    Joined:
    Jul 31, 2008
    Messages:
    1
    Hello,

    Can someone help me, I am trying to create a macro in excel that allows me to create a copy of a worksheet, clear its contents then hyperlink it to a particular cell.
    The problem is that I want it to link a different page to a different cell every time i.e. create sheet 2(3) and link to R3. create sheet 2(4) link to cell R4, but I can only make it so that it creates the copy, deletes the contents and the links cell R2 with Sheet 2(2), at the moment the coding looks like this:

    Sheets("Sheet2").Select
    Sheets("Sheet2").Copy Before:=Sheets(2)
    Sheets("Sheet1").Select
    Range("R2").Select
    ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="", SubAddress:= _
    "'Sheet2 (2)'!A1"


    What would I need to add or change to make it do what I want to?

    Thanks Claire
     
  2. Rollin_Again

    Rollin_Again

    Joined:
    Sep 4, 2003
    Messages:
    4,912
    Can you post a sample workbook?

    Regards,
    Rollin
     
  3. Aj_old

    Aj_old

    Joined:
    Sep 24, 2007
    Messages:
    869
    Try with this:
    Code:
     Sub mu()
        Sheets("Sheet2").Copy Before:=Sheets(2)
        Set sht = ActiveSheet
        sht.Cells.ClearContents
        m = WorksheetFunction.Find("(", sht.Name)
        r = Mid(sht.Name, m + 1, Len(sht.Name) - m - 1)
        
        Sheets("Sheet1").Hyperlinks.Add Anchor:=Sheets("Sheet1").Range("R" & r), Address:="", _
                        SubAddress:="'" & sht.Name & "'!A1"
    
    End Sub
    
     
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/735659

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice