Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hyperlink name based on value of a cell 2

Status
Not open for further replies.

ADE6

Programmer
Apr 4, 2004
93
GB
Hi,

I have the following code,created using the Excel macro recorder.

Is it possible to change the parts that refer to "HELP" so that it refers to cell H25, so that when I change the text within cell H25 and run the macro again it will create a new Hyperlink,called whatever text is displayed in cell H25.


Thanks for the ideas.

Ade


Code:
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="", SubAddress:= _
        "HELP!A1", TextToDisplay:="HELP"




Code:
Sub HYPERLINK()

    
    Range("F45").Select
    ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="", SubAddress:= _
        "HELP!A1", TextToDisplay:="HELP"
    Range("F45").Select
    Selection.Font.Bold = True
    With Selection.Font
        .Name = "Arial"
        .Size = 12
        .Strikethrough = False
        .Superscript = False
        .Subscript = False
        .OutlineFont = False
        .Shadow = False
        .Underline = xlUnderlineStyleSingle
        .ColorIndex = 5
    End With
    
End Sub
 
Perhaps this ?
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="", SubAddress:= _
[H25].Text & "!A1", TextToDisplay:=[H25].Text

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hi,

just refer to the range with the value you want to use:

Code:
Sub HYPERLINK()

    
    With ActiveSheet
	.Hyperlinks.Add Anchor:=Selection, Address:="", _
SubAddress:= "HELP!A1", TextToDisplay:=.Range("H25").Value
   	With  .Range("F45").Font
   		.Bold = True
       		.Name = "Arial"
        		.Size = 12
       		.Strikethrough = False
        		.Superscript = False
       		.Subscript = False
        		.OutlineFont = False
        		.Shadow = False
        		.Underline = xlUnderlineStyleSingle
        		.ColorIndex = 5
    	End With
    End With
 
End Sub

Also, you don't need to select a cell first, you can apply these properties directly.

Cheers,

Roel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top