Run Macro if Cell Contains...

eli_m

Board Regular
Joined
Jun 2, 2022
Messages
160
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!
 
VBA Code:
If Not Target.Find("Create Calendar Invite") Is Nothing Then
That works if I type in the cell "Create Calendar Invite - 02-Dec" it works:
1730170803194.png


but If the formula puts the text in it doesn't work:
1730170832797.png



So I think there's an issue when the formula says it..
 
Upvote 0

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Only other thing I can think of is
VBA Code:
If Not Target.Find("Create Calendar Invite",LookIn:= xlValues) Is Nothing Then
 
Upvote 0
Solution
Only other thing I can think of is
VBA Code:
If Not Target.Find("Create Calendar Invite",LookIn:= xlValues) Is Nothing Then

Sadly that didnt' work either.. I wonder if there is another way to run the macro by clicking the cell if it has Formula Text
 
Upvote 0
The word "Calandar" is definitely a misspelling, and does it actually appear in your formula?
Try correcting it and see if it works

Screenshot 2024-10-29 110611.png
 
Upvote 0
*Giggles*:giggle:
 
Upvote 0
This code has been working well most of the week but every now and then I get an error on line:

If Not Intersect(Selection, Range("U:U")) Is Nothing And Selection.Count = 1 Then

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 Not Target.Find("Create Calendar Invite",LookIn:= xlValues) Is Nothing Then
            Call CalendarInvite
        End If
    End If

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

End Sub

It normally happens when I change the sheet to another, but when I try to recreate it again, it doesn't error again to take a screenshot.

Basically I just want the the below part of the code to run only if I am in Column U so its not running on every SelectionChange:

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


Is there anything I can do to stop this error?
 
Upvote 0
This code has been working well most of the week but every now and then I get an error on line:

If Not Intersect(Selection, Range("U:U")) Is Nothing And Selection.Count = 1 Then

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 Not Target.Find("Create Calendar Invite",LookIn:= xlValues) Is Nothing Then
            Call CalendarInvite
        End If
    End If

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

End Sub

It normally happens when I change the sheet to another, but when I try to recreate it again, it doesn't error again to take a screenshot.

Basically I just want the the below part of the code to run only if I am in Column U so its not running on every SelectionChange:

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


Is there anything I can do to stop this error?

I managed to get the screenshots:
1730434594300.png


1730434619872.png
 
Upvote 0
1- Use "Target" instead of "Selection" may help?
or
2- Do not use "intersect":
If target.column=21 ... (21 is column index of column U)

If they still does not help:

3- Try to exit sub first:
If Intersect(Target, Range("U:U")) is Nothing or Target.count>1 then Exit Sub
 
Upvote 0
1- Use "Target" instead of "Selection" may help?
or
2- Do not use "intersect":
If target.column=21 ... (21 is column index of column U)

If they still does not help:

3- Try to exit sub first:
If Intersect(Target, Range("U:U")) is Nothing or Target.count>1 then Exit Sub
Thanks for that but no luck.

1. Doesn't run the macro

2.
1730437012492.png


3.
1730437050191.png
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,151
Members
453,021
Latest member
Justyna P

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