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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel - Function returning Hyperlink 2

Status
Not open for further replies.

Andrzejek

Programmer
Jan 10, 2006
8,486
5
38
US
I have an Excel where I have a column with some text.
I can easily manipulate this text to create a URL

I would like to create a Function (UDF) that I can use as a Formula that would return a Hyperlink, so if I have something like this:

TextToURL_gvxl40.png


I would like to have this working:

Code:
Option Explicit

Function TextToURL(ByRef strText As String) As Hyperlink   [green]'<<< is that right?
'Manipulate strText to create a URL[/green]

TextToURL = [red]???[/red]

End Function

So I can have this:

TextToURL_01_nsjiw0.png



---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
Hi mintjulep,
It would never occur to me that something like this already exists. Thank you for the information.
 
According to this place Using Excel worksheet functions in Visual Basic I should be able to use the Hyperlink formula in my VBA this way:

Code:
Option Explicit

Function TextToURL(ByRef strText As String) As Hyperlink
Dim s As String

s = Replace(strText, "--", "")

TextToURL = Application.WorksheetFunction.[red]Hyperlink(s, Right(s, 10))[/red]

End Function

but, unfortunately, that does not work. I get an error #VALUE! :-(
I don't even see the [tt]Hyperlink[/tt] when I use [tt]Application.WorksheetFunction.[/tt]

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
Thank you mikrom,
It looks to me that I cannot create my own Formula in VBA and create Hyperlinks in one step [mad]

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
You should be able to use your UDF inside the HYPERLINK() formula in a cell.

Code:
=HYPERLINK(TextToURL(A1),"my Link")

But if your text manipulation is as simple as your last post, then why use a UDF at all?

Code:
=HYPERLINK(SUBSTITUTE(A1, "--", ""), RIGHT(A1, 10))
 
Great! Using UDF inside the HYPERLINK() formula works nice [thumbsup2]
And no, my text manipulation is not as simple as in my post. That was just an example.

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top