Run Macro if Cell Contains...

eli_m

Board Regular
Joined
Jun 2, 2022
Messages
153
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

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
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,227
Messages
6,170,849
Members
452,361
Latest member
d3ad3y3

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