Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Max Max is offline
external usenet poster
 
Posts: 390
Default Assigning a Hyperlink to A Cell that References a Worksheet

I'd like to programatically apply a hyperlink to an active cell that will
point to a named range on another sheet in the same workbook. I haven't had
any luck with the following code:

********
Set sh = Worksheets("Dashboard")
sh.Activate
sh.Cells(p + 5, 2).Value = arrENGINE(i)
sh.Cells(p + 5, 2).Select

sh.Cells(p + 5, 2).Hyperlinks.Add Anchor:=Selection, Address:="",
SubAddress:=arrENGINE(i) _
, TextToDisplay:=Selection.Value
*******

where arrENGINE(i) is a string - example "GF44-123PL_G01"

Any suggestions as to what is going on?
--
Thanks!
Max
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Assigning a Hyperlink to A Cell that References a Worksheet

Say we have a Named Range in Sheet1 called "in_the_box"

Without VBA we can create a hyperlink to this Range with:

=HYPERLINK("#Sheet1!box_in_sheet1","to the box")

We just need the macro to create the formula for us:

Sub hyperput()

'''''''''''''''''''
'
'=HYPERLINK("#Sheet1!box_in_sheet1","to the box")
'
'''''''''''''''''''

dq = Chr(34)
s1 = "=HYPERLINK(" & dq & "#Sheet1!box_in_sheet1" & dq
s2 = "," & dq & "to the box" & dq & ")"
Selection.Formula = s1 & s2
End Sub


I dq because embedding double quotes gives me a headache

--
Gary''s Student - gsnu200722


"Max" wrote:

I'd like to programatically apply a hyperlink to an active cell that will
point to a named range on another sheet in the same workbook. I haven't had
any luck with the following code:

********
Set sh = Worksheets("Dashboard")
sh.Activate
sh.Cells(p + 5, 2).Value = arrENGINE(i)
sh.Cells(p + 5, 2).Select

sh.Cells(p + 5, 2).Hyperlinks.Add Anchor:=Selection, Address:="",
SubAddress:=arrENGINE(i) _
, TextToDisplay:=Selection.Value
*******

where arrENGINE(i) is a string - example "GF44-123PL_G01"

Any suggestions as to what is going on?
--
Thanks!
Max

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Assigning a Hyperlink to A Cell that References a Worksheet

First, that doesn't look like a valid name to me. I'd replace that hyphen with
an underscore.

and then maybe...

With sh
.Hyperlinks.Add Anchor:=.Cells(p + 5, 2), _
Address:="", _
SubAddress:=arrENGINE(i), _
TextToDisplay:=.Cells(p + 5, 2).Value
end with

(untested)

Max wrote:

I'd like to programatically apply a hyperlink to an active cell that will
point to a named range on another sheet in the same workbook. I haven't had
any luck with the following code:

********
Set sh = Worksheets("Dashboard")
sh.Activate
sh.Cells(p + 5, 2).Value = arrENGINE(i)
sh.Cells(p + 5, 2).Select

sh.Cells(p + 5, 2).Hyperlinks.Add Anchor:=Selection, Address:="",
SubAddress:=arrENGINE(i) _
, TextToDisplay:=Selection.Value
*******

where arrENGINE(i) is a string - example "GF44-123PL_G01"

Any suggestions as to what is going on?
--
Thanks!
Max


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Assigning a Worksheet Name to a Cell bcw_now Excel Worksheet Functions 3 May 14th 09 04:46 PM
Hyperlink cell references Bob Excel Worksheet Functions 2 March 12th 09 03:57 PM
Assigning macro to a hyperlink Mantades Excel Worksheet Functions 0 June 9th 05 11:34 AM
Assigning a Hyperlink to a CommandButton Andy T Excel Discussion (Misc queries) 2 December 21st 04 12:31 PM
Assigning a Hyperlink to a Macro Paul Excel Discussion (Misc queries) 3 December 16th 04 05:34 PM


All times are GMT +1. The time now is 11:20 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"