Results 1 to 5 of 5

macro creates new sheet and names it, need to create hyperlink to new sheet on main sheet

Threaded View

  1. #1
    Registered User
    Join Date
    01-10-2017
    Location
    IA
    MS-Off Ver
    2013
    Posts
    3

    Question macro creates new sheet and names it, need to create hyperlink to new sheet on main sheet

    I have a workbook I've made that takes a sheet used as a template, copies it and creates a new sheet, and names the new sheet based on the input of a user form textbox. It also takes that input and places it in a cell ("A7") on the main page (page named 'Main')

    I need to then create a hyperlink in that cell on "Main" for the new sheet. The new sheet name will always be on sheet("Main").range("A7")

    Everything works fine except this piece of code:

    link = """Name & "!A1""
     Sheets("Main").Range("A7").Select
        ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="", SubAddress:= _
            link, TextToDisplay:=Name
    The subaddress needs to read (including quotes, and 'name' is the sheet name which will be different every time)
    "name!A1"

    *to answer questions before they're asked
    -The macro will be used to create several sheets
    -it will be updated often, and new sheets will be created via macro so manually creating hyperlinks to the sheets isn't optimal

    here are the relevant lines of code:

    Dim Name As String
    Dim link As Long
    
    Name = Me.TextBox1.Text
        Sheets("main").Activate
        Sheets("Main").Rows("7:7").Select
        Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
    
        Sheets("Template").Select
    
        Sheets("Template").Copy Before:=Sheets(2)
        
        ActiveSheet.Name = Name
    
    Sheets("Main").Range("A7").Value = Name
    
    'something is wrong below this
    
    link = """Name & "!A1""
    
     Sheets("Main").Range("A7").Select
        ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="", SubAddress:= _
            link, TextToDisplay:=Name
    Last edited by jeffreybrown; 02-02-2020 at 09:55 PM. Reason: Please use code tags!

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Macro that creates new sheet and is capable of populating new sheet with formulas
    By Pedrot1811 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-12-2019, 09:08 AM
  2. Create automatically new sheet based on main data sheet
    By manharji in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-05-2016, 11:14 AM
  3. Macro to create a Result Sheet from Data and Names Sheet
    By pnasir in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-24-2016, 05:29 AM
  4. [SOLVED] Create an Array which has Sheet Names excluding a Few Sheet Names to be used in a MACRO
    By e4excel in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 11-29-2013, 03:24 PM
  5. [SOLVED] Simple macro to create list of sheet names and the contents of cells A1 & N1 of each sheet
    By atcsmh in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-15-2013, 11:11 AM
  6. Macro to create sheet, rename sheet, and hyperlink to it
    By prescottfarm in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-31-2013, 04:46 PM
  7. Macro in sheet one to create a search for names in sheet 2
    By CamillaKb in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-16-2012, 08:17 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