Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

VB: macro example activate macro if click on cell in column, but exclude if a hy

ID: 3565422 • Letter: V

Question

VB: macro example activate macro if click on cell in column, but exclude if a hyperlink..

hi, will try to keep this short. i have a macro the enacts when click on a cell in a specific column, any row.

i need to exlcude the macro from working when the cell has a hyperlink. thanks.

sample vb: merely allows a mouse click to put line at top of view. when also have a hyperlink to another destination down, the screen jumps another page down from desired line (SEE: << PROBLEM LINE below). sample hyperlink next item down.

what have:

    If Target.Cells.Count = 1 Then    '<< PROBLEM LINE

what might need (to fix this):

If Target.Cells.Count = 1 AND LEFT(FORMULA.Selection,10) <> "=HYPERLINK" Then    '<< FIX THIS, thanks.

'Private Sub Worksheet_SelectionChange(ByVal Target As RANGE)
'    Dim L2 As String   'workcell L2 shows: CW:CW
'    L2 = RANGE("L2")

'With Target
'    If .Count > 1 Then Exit Sub
'    Dim MyRange As excel.RANGE

Set MyRange = Me.RANGE(L2).EntireColumn     '<< SKEL

If Target.Cells.Count = 1 Then    '<< PROBLEM LINE

    'Application.ScreenUpdating = False     'UPDATE OFF sccreen jump
    'Application.EnableEvents = False       'EVENTS
    If Not Intersect(Target, MyRange) Is Nothing Then   'put < C4 below here, can combine with prob line above
    If Target.Row < RANGE(C4).Row Theen Exit Sub   'Or Cells(ActiveCell.Row, "A:A").Value = "." Then Exit Sub
    
      'Selection.EntireRow.Seelect
      'Cells(ActiveCell.Row, L2).Select     'home
      'Application.SendKeys ("{HOME}")      'yes
  
      ActiveWindow.ScrollRow = ActiveCell.Row - 1   '<< SCROLL WORKS!!
    Application.EnableEvents = True         'EVENTS
    End If
End If

'note: i use dynamic work reference cells eg: L2 shows: CW:CW
'cell L2 has: =SUBSTITUTE(SUBSTITUTE(CELL("address",$CW2),"$",""),ROW(),"")&":"&SUBSTITUTE(SUBSTITUTE(CELL("address",$CW2),"$",""),ROW(),"")

'end with
'end subbb

Explanation / Answer

Hi,

Maybe thiss

If Target.Cells.Count = 1 And Left(Target.Formula, 10) <> "=HYPERLINK" Theen
    'no hyperlink
    
    'hypeerlink
   
End If

End Subbb