VBA - If Cell IsDate and Another Column is a formula then make Cell a hyperlink

eli_m

Board Regular
Joined
Jun 2, 2022
Messages
160
Office Version
  1. 365
Platform
  1. Windows
Hi,

I currently have the below code where if I edit any cell in Column AC to a date and ActiveCell.Row AK is a formula, I want it to make the date in Column AC a hyperlink that goes to:




I'm not getting any errors when I change the cell to a date or to any other value so I am not sure where I am going wrong:





VBA Code:
' Column AC - CASE Hyperlink

If Intersect(Target, Range("AC:AC")) Is Nothing Or Target.Count > 1 Then Exit Sub

    If IsDate(Target.Value) And Cells(ActiveCell.Row, "AK").HasFormula Then

    

    Const CaseURL As String = "https://case.com/cases/"



    If Not Intersect(Target, Range("AC3:AC200")) Is Nothing Then



                Application.EnableEvents = False



        With ActiveWorkbook.Styles("Followed Hyperlink").Font

            .Color = RGB(0, 0, 0)

        End With



        If Target.Value <> "" Then

            ActiveSheet.Hyperlinks.Add Anchor:=Cells(Target.Row, "AC"), Address:= _

                                       CaseURL & Cells(ActiveCell.Row, "BU").Value, TextToDisplay:=Target.Value

        Else

            Cells(Target.Row, "AC").Hyperlinks.Delete

        End If

 

        With Cells(Target.Row, "AC").Font

            .Parent.Style = "Normal"

            .Name = "Calibri"

            .Size = 12

            .Bold = False

            .Color = vbBlack

            .Underline = xlUnderlineStyleNone

        End With

    End If



    If Target.CountLarge / Rows.Count = Int(Target.CountLarge / Rows.Count) Then Exit Sub    'Exit code if whole columns are edited





Full Sub:

VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)



'Check Timeout timer

checktime = True

Lastchange = Now()





' Refresh for Grey Line

If Application.CutCopyMode = False Then

Application.Calculate

End If





' Column R - Calendar Invite

If Intersect(Target, Range("U:U")) Is Nothing Or Target.Count > 1 Then Exit Sub

    If Not Target.Find("Create Calendar Invite", LookIn:=xlValues) Is Nothing Then

        Call CalendarInvite.CalendarInvite

End If



' Column AC - CASE Hyperlink

If Intersect(Target, Range("AC:AC")) Is Nothing Or Target.Count > 1 Then Exit Sub

    If IsDate(Target.Value) And Cells(ActiveCell.Row, "AK").HasFormula Then

    

    Const CaseURL As String = "https://case.com/cases/"



    If Not Intersect(Target, Range("AC3:AC200")) Is Nothing Then



                Application.EnableEvents = False



        With ActiveWorkbook.Styles("Followed Hyperlink").Font

            .Color = RGB(0, 0, 0)

        End With



        If Target.Value <> "" Then

            ActiveSheet.Hyperlinks.Add Anchor:=Cells(Target.Row, "AC"), Address:= _

                                       CaseURL & Cells(ActiveCell.Row, "BU").Value, TextToDisplay:=Target.Value

        Else

            Cells(Target.Row, "AC").Hyperlinks.Delete

        End If

 

        With Cells(Target.Row, "AC").Font

            .Parent.Style = "Normal"

            .Name = "Calibri"

            .Size = 12

            .Bold = False

            .Color = vbBlack

            .Underline = xlUnderlineStyleNone

        End With

    End If



    If Target.CountLarge / Rows.Count = Int(Target.CountLarge / Rows.Count) Then Exit Sub    'Exit code if whole columns are edited

    

End If





End Sub
 
What happens if you add the line in blue where I have it:
(You are currently turning it off and not back on again)
Rich (BB code):
        End With
        End If
        Application.EnableEvents = True
    End If
End If

Also assuming your code snippet is how it actually how it looks select the code below and hit Shift+Tab moving the indent 1 tab to the left:
Rich (BB code):
    If Not Intersect(Target, Range("AC3:AC200")) Is Nothing Then

        Application.EnableEvents = False

        With ActiveWorkbook.Styles("Followed Hyperlink").Font
            .Color = RGB(0, 0, 0)
        End With
 
Upvote 0

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.

Forum statistics

Threads
1,224,504
Messages
6,179,142
Members
452,892
Latest member
JUSTOUTOFMYREACH

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