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

Status
Not open for further replies.

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
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Status
Not open for further replies.

Forum statistics

Threads
1,224,847
Messages
6,181,337
Members
453,032
Latest member
Pauh

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