Conditional "FollowHyperlink"???????

gheyman

Well-known Member
Joined
Nov 14, 2005
Messages
2,047
Office Version
  1. 365
Platform
  1. Windows
I need to enter a condition -

Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)

If Range("Z84") > 1 And
Range("D10") = "" Then
UserForm69.Show
End If


- to meet before the hyperlink takes you to its destination. The problem is the this is a "FollowHyperlink" action. It takes me to the next page and then displays the Userform. Basically I dont want the user to be able to leave the page via hyperlink if the two conditions above are not met.

HELP!!!!!!!!!!!!!!!!
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type

erik.van.geit

MrExcel MVP
Joined
Feb 1, 2003
Messages
17,832
Hi, gheyman,
this is not really my favorite kind of code
let's call it a workaround
try this to check if it does what you would like
Code:
Option Explicit

Public PrevSel As Range 'previous selection

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'Erik Van Geit
'051116 0026

Dim hyp As String
Dim Cell As Range
Dim ThisCell As Range


If Selection.Count > 1 Then GoTo skip

Set ThisCell = Target

On Error Resume Next
hyp = Target.Hyperlinks(1).SubAddress
On Error GoTo 0

    If Not hyp = "" Then
    Set Cell = ActiveSheet.Range(Right(hyp, Len(hyp) - InStr(1, hyp, "!")))
        If Range("Z84") > 1 And Range("D10") = "" Then
            If PrevSel Is Nothing Then
            Application.Goto reference:=ThisCell.Offset(1, 0)
            Else
            Application.Goto reference:=PrevSel
            End If
        UserForm69.Show 
        End If
    End If
skip:
Set PrevSel = ActiveCell
End Sub
kind regards,
Erik
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,504
Messages
5,832,106
Members
430,111
Latest member
Francis Xavier

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