+ Reply to Thread
Results 1 to 4 of 4

problem obtaining correct Text-to-be-displayed in hyperlink creation

Hybrid View

dschmitt problem obtaining correct... 10-15-2014, 09:39 PM
dschmitt Re: problem obtaining correct... 10-15-2014, 10:33 PM
AlphaFrog Re: problem obtaining correct... 10-15-2014, 10:43 PM
dschmitt Re: problem obtaining correct... 10-15-2014, 10:55 PM
  1. #1
    Valued Forum Contributor
    Join Date
    02-21-2010
    Location
    Tokyo, Japan
    MS-Off Ver
    Excel 2007
    Posts
    502

    problem obtaining correct Text-to-be-displayed in hyperlink creation

    I am using the sub below to create hyperlinks. The problem that I have with this sub is that it converts what looks like a date into date format and what looks like a number to a number. What I want is that it uses the 4 characters as text. How do I avoid that what looks like a number is converted to number and what looks like a date is converted to date format.

    Sub MakeHyperlinks()
    
        Application.ScreenUpdating = False
    
        Dim LastRowA As Long
        Dim x As Long
    
        LastRowA = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row
    
        For x = 1 To LastRowA
    
            Cells(x, 3) = Cells(x, 2)
            Range("C" & x).Select
            y = Cells(x, 1)
            Selection.Hyperlinks.Add Anchor:=Selection, Address:=ActiveSheet.Range(Selection.Address).Value, _
            TextToDisplay:=y
    
        Next x
    
        Application.ScreenUpdating = True
    
    End Sub
    HTML Code: 
    HTML Code: 
    Last edited by dschmitt; 10-15-2014 at 10:09 PM.

  2. #2
    Valued Forum Contributor
    Join Date
    02-21-2010
    Location
    Tokyo, Japan
    MS-Off Ver
    Excel 2007
    Posts
    502

    Re: problem obtaining correct Text-to-be-displayed in hyperlink creation

    I found the solution.
    Instead of assigning a Text-To-Be-Displayed in the Hyperlink.Add statement I linked the hyperlink address to an existing string.

    Sub MakeHyperlinks2()
    
        Application.ScreenUpdating = False
    
        Dim LastRowA As Long
        Dim x As Long
    
        LastRowA = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row
    
        For x = 1 To LastRowA
    
            Cells(x, 3) = Cells(x, 1)
            Range("B" & x).Select
            Selection.Hyperlinks.Add Anchor:=Cells(x, 3), Address:=ActiveSheet.Range(Selection.Address).Value
    
        Next x
    
        Application.ScreenUpdating = True
    
    End Sub

  3. #3
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: problem obtaining correct Text-to-be-displayed in hyperlink creation

    Another method...

    Sub MakeHyperlinks()
        
        Dim x As Long
        
        Application.ScreenUpdating = False
        
        For x = 1 To ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row
        
            ActiveSheet.Hyperlinks.Add Anchor:=Cells(x, "C"), Address:=Cells(x, "B").Value, _
                TextToDisplay:="'" & Cells(x, "A").Value
        
        Next x
        
        Application.ScreenUpdating = True
        
    End Sub
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  4. #4
    Valued Forum Contributor
    Join Date
    02-21-2010
    Location
    Tokyo, Japan
    MS-Off Ver
    Excel 2007
    Posts
    502

    Re: problem obtaining correct Text-to-be-displayed in hyperlink creation

    AlphaFrog, it works. Interestingly. adding ' in front of the 4 characters in column A doesn't work.

+ 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] Need help obtaining correct formula to handle Gross Profit Margin
    By coreytroy in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 09-26-2014, 01:33 AM
  2. ASCII text file creation problem
    By annep in forum Excel General
    Replies: 2
    Last Post: 09-25-2006, 09:08 PM
  3. Not obtaining the correct result
    By ZT in forum Excel General
    Replies: 1
    Last Post: 05-03-2006, 02:25 PM
  4. Chart data labels are not correct or not displayed
    By Bolton User in forum Excel Charting & Pivots
    Replies: 3
    Last Post: 04-11-2006, 12:30 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