LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default Function behaviour, can someone explain please?

Hi Guys,

I have a custom function that finds a hyperlink/s in a cell.
It wasn't written by me but sourced on the web somewhere, unknown
origin.

Here is the code...

Function TextLink(cellT As Range, Optional defVal As Variant)

If (cellT.Range("A1").Hyperlinks.Count < 1) Then
TextLink = defVal
Else
TextLink = cellT.Range("A1").Hyperlinks(1).Address
End If
End Function


This works fine, however what it does do is seems to get called by
totally unrelated code in other worksheets in the same workbook. I
don't know why, and I would like to know why.

I have rewrote the code with this...

Function TextLink(cellT As Range, Optional defVal As Variant)

If (cellT.Offset(0, 0).Hyperlinks.Count < 1) Then
TextLink = defVal
Else
TextLink = cellT.Offset(0, 0).Hyperlinks(1).Address
End If
End Function

This also works but doesn't (after testing) seem to get called by other
seperate code in other worksheets in the same workbook.

Now in the first code the cellT range is A2 and the function is sat in
B2. I'm extracting the first 55 characters of the hyperlink. I'm using
this..

=LEFT(TextLink(A2,""),55)

Works ok. Returns an empty string if there's no hyperlink.

The problem as I see it is the .Range("A1") part of the original
function. Is it open to be called by any sheet at any time if A1 is
selected?

It isn't a problem while the code runs at normal speed, but when I'm
stepping through to debug I'm getting this function being called and
insisting on looping through itself possibly hundreds of times before I
get sick and have to end the debug.

I'm quite happy at the rate I'm learning VBA, but I'm getting stuck on
functions and their behaviour more and more often.

Can anyone shed any light on this please?

Thanks guys,

Ron
 
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
Please explain YIELDMAT function JoeU2004 Excel Worksheet Functions 9 September 10th 09 02:04 AM
Large function - Please explain Danny Excel Worksheet Functions 5 December 18th 07 08:34 PM
Please explain function/formula Tara H Excel Worksheet Functions 6 July 24th 06 07:16 PM
Custom Function behaviour? Ron[_28_] Excel Programming 7 December 30th 04 11:10 PM
Behaviour of VBA ROUND function Microsoft Forum Excel Programming 3 December 30th 04 04:16 PM


All times are GMT +1. The time now is 07:21 AM.

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

About Us

"It's about Microsoft Excel"