+ Reply to Thread
Results 1 to 4 of 4

add hyperlink to a cell

  1. #1
    Registered User
    Join Date
    11-20-2017
    Location
    CA
    MS-Off Ver
    2016
    Posts
    26

    add hyperlink to a cell

    Hello everyone,

    I am trying to add hyperlink in a cell, it works find :

    ActiveCell.FormulaR1C1 = "=HYPERLINK(""[Workbook.xlsx]Sheet1!A1"",""CLICK HERE"")"


    But when I am trying to change the "CLICK HERE" ,I want to add variables in it, it doesn't work this time. please advise:



    Dim mySheetName As String

    mySheetName = "sheet12"

    ActiveCell.FormulaR1C1 = "=HYPERLINK(""[Workbook.xlsx]Sheet1!A1"",""CLICK HERE to link to : " & mySheetName ")"

    Thanks a lot!

  2. #2
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: add hyperlink to a cell

    try
    Please Login or Register  to view this content.
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    although I would expect the sheet name in the friendy name to match what is in the hyperlink
    so..
    Please Login or Register  to view this content.
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Last edited by kev_; 02-23-2018 at 03:49 AM.
    Click *Add Reputation to thank those who helped you. Ask if anything is not clear

  3. #3
    Registered User
    Join Date
    11-20-2017
    Location
    CA
    MS-Off Ver
    2016
    Posts
    26

    Re: add hyperlink to a cell

    This part is magic:

    """ & mystr & """


    if I want to use the variable in the hyperlink, I have to add "&"s and these quotes to surround it.

    it works great but I don't know why.

    Thanks!

  4. #4
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: add hyperlink to a cell

    The "magic" .....
    Please Login or Register  to view this content.
    could also be written out like this:
    Please Login or Register  to view this content.
    to return this formula:
    =HYPERLINK( " [Workbook.xlsx]sheet12!A1 " , " CLICK HERE to link to : sheet12 " )

    Excel requires the 4 quote marks in the derived formula
    - but VBA requires the formula string itself to be inside quote marks
    - so we need to place quote marks inside quote marks

    Quote marks can be inserted inside quote marks using 2 methods:
    - either double up the quote marks
    - or use chr(34) which is the character code for a quote mark
    Last edited by kev_; 02-23-2018 at 04:29 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] With Hyperlink formula & vba, I want to copy text of hyperlink to the cell it's linked to
    By Freakytone in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-13-2017, 05:46 PM
  2. Using a hyperlink to select a cell and instantly activate that cell's hyperlink
    By dkgbeast in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-01-2016, 02:43 PM
  3. Replies: 2
    Last Post: 04-23-2014, 11:25 AM
  4. Can you add a hyperlink to a cell that already contains a rollover hyperlink?
    By Muzza86 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-23-2014, 08:02 AM
  5. [SOLVED] Excel 2010 Create a macro to check if cell contains hyperlink then apply hyperlink style
    By chasidar in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-12-2013, 04:48 AM
  6. [SOLVED] How do I create a hyperlink to a cell with the hyperlink function
    By S. Bevins in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 07-20-2006, 03:06 PM
  7. script to hyperlink and reference a cell value in the hyperlink
    By Natasha D. in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-17-2006, 02:43 PM

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