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

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
No 2: Remove "Is Nothing"
No 3: Remove "End If"
No 2:
1730437887684.png


Am I keeping the NOT? As my old code was:
If Not Intersect(Selection, Range("U:U")) Is Nothing And Selection.Count = 1 Then


No 3. This seems to work so I'll give it a test run for a few days
 
Upvote 0
No 2: Just only:
PHP:
If Target.Column=21 And Target.Count>1 then
to let Excel know the target will be / only be in column U.
 
Upvote 0
Try


VBA Code:
If Not Application.Intersect(Selection, Range("U:U")) Is Nothing And Selection.Count = 1 Then
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,183
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