Determing if a Hyperlink Exists

mj0lnr

New Member
Joined
May 6, 2003
Messages
46
All,

This one might be fairly simple (of course if that was simple, I'd have figured it out by now) but, what I'd like to accomplish is the following:
  • 1)Comb thru a column (H) and check if a hyperlink exists
    2)If YES, leaves it alone
    3)If NOT, selects the cell and checks the rest of the H column for the same condition
    4)Selects all cells WITHOUT a hyperlink
    5)Determines 1st cell without a hyperlink

Many Thanks in advance,
A.
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.

brettvba

MrExcel MVP
Joined
Feb 18, 2002
Messages
1,030
That is fairly easy do you want the cell to go red or something if it doesn;t have a hyperlink?

Brett
 

mj0lnr

New Member
Joined
May 6, 2003
Messages
46
oh no, I just need to have it selected for my next sub to run.....

A.
 

mj0lnr

New Member
Joined
May 6, 2003
Messages
46
oh and one other thing, I need that 1st cell without a hyperlink to be a part of another subroutine. Is that possible? Seeing that it's a variable, would it be able to be incorportated into the next sub?

again, many thanks,
A.
 

NateO

Legend
Joined
Feb 17, 2002
Messages
9,700

ADVERTISEMENT

I can't see any reason to select anything... What are in these non-hyperlink cells? Nothing?

You'll incorporate it into the same procedure or pass it.
 

NateO

Legend
Joined
Feb 17, 2002
Messages
9,700

ADVERTISEMENT

No, not really:

<font face=Courier New><SPAN style="color:darkblue">Sub</SPAN> kdsjfkdsf()
<SPAN style="color:darkblue">Dim</SPAN> cl <SPAN style="color:darkblue">As</SPAN> Range, y <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">String</SPAN>
<SPAN style="color:darkblue">On</SPAN> <SPAN style="color:darkblue">Error</SPAN> <SPAN style="color:darkblue">Resume</SPAN> <SPAN style="color:darkblue">Next</SPAN>
<SPAN style="color:darkblue">For</SPAN> <SPAN style="color:darkblue">Each</SPAN> cl <SPAN style="color:darkblue">In</SPAN> [h:h].SpecialCells(xlConstants, 2)
    y = cl.Hyperlinks(1).Name
    <SPAN style="color:darkblue">If</SPAN> Err.Number <> 0 <SPAN style="color:darkblue">Then</SPAN>
        MsgBox cl.Address
        Err.Clear
        <SPAN style="color:darkblue">Exit</SPAN> <SPAN style="color:darkblue">Sub</SPAN> <SPAN style="color:green">'******Quit after first*********</SPAN>
    <SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">If</SPAN>
<SPAN style="color:darkblue">Next</SPAN>
<SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">Sub</SPAN></FONT>

If you don't want them all, don't exit the sub. :)
 

mj0lnr

New Member
Joined
May 6, 2003
Messages
46
oh sorry Nate....I guess I should have said that, it needs to start at H23 and probably never go over H200 :confused:

A.
 

NateO

Legend
Joined
Feb 17, 2002
Messages
9,700
<font face=Courier New><SPAN style="color:darkblue">Sub</SPAN> kdsjfkdsf()
<SPAN style="color:darkblue">Dim</SPAN> cl <SPAN style="color:darkblue">As</SPAN> Range, y <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">String</SPAN>
<SPAN style="color:darkblue">On</SPAN> <SPAN style="color:darkblue">Error</SPAN> <SPAN style="color:darkblue">Resume</SPAN> <SPAN style="color:darkblue">Next</SPAN>
<SPAN style="color:darkblue">For</SPAN> <SPAN style="color:darkblue">Each</SPAN> cl <SPAN style="color:darkblue">In</SPAN> Range([h23], [h65536].End(3))
    y = cl.Hyperlinks(1).Name
    <SPAN style="color:darkblue">If</SPAN> Err.Number <> 0 <SPAN style="color:darkblue">Then</SPAN>
        MsgBox cl.Address
        Err.Clear
        <SPAN style="color:darkblue">Exit</SPAN> <SPAN style="color:darkblue">Sub</SPAN> <SPAN style="color:green">'******Quit after first*********</SPAN>
    <SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">If</SPAN>
<SPAN style="color:darkblue">Next</SPAN>
<SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">Sub</SPAN></FONT>
 

brettvba

MrExcel MVP
Joined
Feb 18, 2002
Messages
1,030
Mines probably not as snazzy as Nates but if your wanting to select the cell with the first hyperlink in it then this will work.

Code:
Sub SelectFirstHL()
Set x = ThisWorkbook.Sheets(1).Range("h23:h200").Hyperlinks
    If x.Count > 0 Then
        Cells(x(1).Range.Row, x(1).Range.Column).Select
    End If
End Sub

Brett
 

Watch MrExcel Video

Forum statistics

Threads
1,130,118
Messages
5,640,216
Members
417,131
Latest member
Seanr19871

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
Top