GetURL

handysmurf

Board Regular
Joined
Jan 17, 2015
Messages
114
Office Version
  1. 365
Platform
  1. Windows
I have a sub to display the URL of a link for me. But it sometimes returns a 0 instead of the link.

Public Function GetURL(Cell As Range, Optional default_value As Variant) As Variant
Dim output As Variant
If (Cell.Range("A1").Hyperlinks.Count <> 1) Then
output = default_value
Else
output = Cell.Range("A1").Hyperlinks(1).Address
End If
GetURL = output
End Function

Help ... it's annoying.
 
You've got to be more clear, concise and forthcoming - and answer questions otherwise no one can help you. After 10 posts I might understand what you have and what is needed. Here's my last guess:

- you have dates in col A; a hyperlink in some, but not all rows in col B. Where B contains a link, the code should return the path of the hyperlink contained in B, not the display text of the hyperlink. Where there is no hyperlink as in rows 2 and 4 below, return the value from col C on the same row (what looks like 1st row in table below is really the column headers, so 1st row has a link)

ABC
5/31/23LinkD:\OneDrive\Owen Divorce\1 (1).jpgrow 1
5/31/23D:\OneDrive\Owen Divorce\1 (1).jpgrow 2
5/31/23LinkD:\OneDrive\Owen Divorce\1 (1).jpg
5/31/23D:\OneDrive\Owen Divorce\1 (1).pngrow 4
6/01/23LinkD:\OneDrive\Owen Divorce\1 (1).png
6/01/23LinkD:\OneDrive\Owen Divorce\1 (1).png
6/01/23LinkD:\OneDrive\Owen Divorce\1 (2).png
6/01/23LinkD:\OneDrive\Owen Divorce\1 (3).jpg
6/01/23LinkD:\OneDrive\Owen Divorce\1 (3).jpg

If that's it, and I manage to code something and you come back and say, no the hyperlinks are in column C (or whatever is not correct/disclosed), you'll be closer I guess, but that will be it for me.
 
Upvote 0

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Actually .... don't worry about it ... sorry ... I just realized that it would be quicker and easier to have the link reference the address in the next cell instead of this way.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top