ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How Do I Trap #VALUE! (https://www.excelbanter.com/excel-programming/291778-how-do-i-trap-value.html)

Robert P. Stearns

How Do I Trap #VALUE!
 
I would like to extract the hyperlink from a cell.
I found a nice example on http://www.ozgrid.com/VBA/HyperlinkAddress.htm
which defined the function GetAddress as:

Function GetAddress(HyperlinkCell As Range)
GetAddress = Replace HyperlinkCell.Hyperlinks(1).Address, "mailto:", "")
End Function
In cell A2, you can enter the function =GetAddress(A1) to extract the
hyperlink from cell A1.In other cells where I do not have a hyperlink the
function returns #VALUE!. How do I change the function to return "" instead
of #VALUE!?



Bernie Deitrick

How Do I Trap #VALUE!
 
Robert,

Function GetAddress(HyperlinkCell As Range)
GetAddress = ""
On Error Resume Next
GetAddress = Replace( _
HyperlinkCell.Hyperlinks(1).Address, "mailto:", "")
End Function

HTH,
Bernie
MS Excel MVP

"Robert P. Stearns" wrote in message
news:zROYb.71578$uV3.527746@attbi_s51...
I would like to extract the hyperlink from a cell.
I found a nice example on http://www.ozgrid.com/VBA/HyperlinkAddress.htm
which defined the function GetAddress as:

Function GetAddress(HyperlinkCell As Range)
GetAddress = Replace HyperlinkCell.Hyperlinks(1).Address, "mailto:", "")
End Function
In cell A2, you can enter the function =GetAddress(A1) to extract the
hyperlink from cell A1.In other cells where I do not have a hyperlink the
function returns #VALUE!. How do I change the function to return ""

instead
of #VALUE!?





Robert P. Stearns

How Do I Trap #VALUE!
 
Bernie,

That did exactly what I wanted.

Thank You!

"Bernie Deitrick" <deitbe @ consumer dot org wrote in message
...
Robert,

Function GetAddress(HyperlinkCell As Range)
GetAddress = ""
On Error Resume Next
GetAddress = Replace( _
HyperlinkCell.Hyperlinks(1).Address, "mailto:", "")
End Function

HTH,
Bernie
MS Excel MVP

"Robert P. Stearns" wrote in message
news:zROYb.71578$uV3.527746@attbi_s51...
I would like to extract the hyperlink from a cell.
I found a nice example on http://www.ozgrid.com/VBA/HyperlinkAddress.htm
which defined the function GetAddress as:

Function GetAddress(HyperlinkCell As Range)
GetAddress = Replace HyperlinkCell.Hyperlinks(1).Address, "mailto:",

"")
End Function
In cell A2, you can enter the function =GetAddress(A1) to extract the
hyperlink from cell A1.In other cells where I do not have a hyperlink

the
function returns #VALUE!. How do I change the function to return ""

instead
of #VALUE!?








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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com