Run Macro if Cell Contains...

eli_m

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

In my worksheet, I have Column U that sometimes has "Create Calendar Invite - DATEHERE" in the cell.

I want it so if any cell in Column U has "Create Calendar Invite*" in it and then I click that cell, it runs a Macro I have set up named 'CalendarInvite'

Is there a way to make a hyperlink to run a macro or does it have to be VBA?

I've tried the below with no success:

VBA Code:
If Not Intersect(Selection, Range("U:U")) Is Nothing And Selection.Count = 1 Then
        If InStr(1, Cells(ActiveCell.Row, "U").Value, "Create Calendar Invite*") > 0 Then
            Call CalendarInvite
        End If
    End If


Full code:
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Application.CutCopyMode = False Then
Application.Calculate ' Refresh for Grey Line
End If

If Not Intersect(Selection, Range("U:U")) Is Nothing And Selection.Count = 1 Then
        If InStr(1, Cells(ActiveCell.Row, "U").Value, "Create Calendar Invite*") > 0 Then
            Call CalendarInvite
        End If
    End If

'Check Timeout timer
checktime = True
Lastchange = Now()

End Sub

Thanks in advance!
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Try this:

VBA Code:
If Not Intersect(Selection, Range("U:U")) Is Nothing And Selection.Count = 1 Then
    If Target.Value Like "Create Calendar Invite*" Then
        Call CalendarInvite
    End If
End If
 
Upvote 0
Try this:

VBA Code:
If Not Intersect(Selection, Range("U:U")) Is Nothing And Selection.Count = 1 Then
    If Target.Value Like "Create Calendar Invite*" Then
        Call CalendarInvite
    End If
End If

Thanks for your help! Sadly that didn't work. I think it has to do with the fact that the "Create Calendar Invite*" comes from the Formula:

Excel Formula:
=IF(ISBLANK([@[Surgery Date]]),"",
IF(AND([@[Hospital Type]]="Private",COUNTIF('Rooms Form'!$A$1:$A$50,[@Surgeon])>0,[@[Surgery Date Checker]]="No Date"),
"Automatically Created - 25-Dec",
IF([@[Surgery Date Checker]]="No Date","Surgery Date TBC",
IF(OR(ISNUMBER([@[Loan Booking Text Date]]),AND([@[Hospital Type]]="Private",COUNTIF('Rooms Form'!$A$1:$A$50,[@Surgeon])>0)),CONCATENATE("Create Calandar Invite - ",TEXT([@[Surgery Date]],"dd-MMM")),""))))

Is there a way around this?

Also when I type the text in the cell I get this error:
1730169109272.png
 
Upvote 0
Try typing
VBA Code:
Call CalendarInvite.[NameOfSub]
no brackets obviously.
 
Upvote 0
T
Try typing
VBA Code:
Call CalendarInvite.[NameOfSub]
no brackets obviously.
That worked but now I just need to get the other part working as it doesn't work when the formula says "Create Calendar Invite"
 
Upvote 0
VBA Code:
If Not Target.Find ("Create Calendar Invite") = Nothing Then
 
Last edited:
Upvote 0
VBA Code:
If Target.Value = "Create Calendar Invite" Then

Just confirming my whole code which didn't work:
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Application.CutCopyMode = False Then
Application.Calculate ' Refresh for Grey Line
End If

If Not Intersect(Selection, Range("U:U")) Is Nothing And Selection.Count = 1 Then
    If Target.Value = "Create Calendar Invite" Then
        Call CalendarInvite.CalendarInvite
    End If
End If

'Check Timeout timer
checktime = True
Lastchange = Now()

End Sub

I also tried with *:
If Target.Value = "Create Calendar Invite" Then
 
Upvote 0
VBA Code:
If Not Target.Find("Create Calendar Invite") Is Nothing Then
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,182
Members
452,615
Latest member
bogeys2birdies

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