Trigger a macro by clicking in column B

USAMax

Well-known Member
Joined
May 31, 2006
Messages
843
Office Version
  1. 365
Platform
  1. Windows
I have been righting macros for years but I have never written one with a trigger. I don't even know what to search for.

FUNCTION NEEDED
When some clicks on a cell in column B
° If the cell is blank I need a check mark and then to run the macro I have written.
° If the cell is not blank I need a check mark and then to run the macro I have written.

This should be simple and I know where to write the code for the sheet I just don't know how to trigger it. The only other question is what would happens if they select B2 through B6 or A2 through F2?

Thanks,

Dave
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
FUNCTION NEEDED
When some clicks on a cell in column B
° If the cell is blank I need a check mark and then to run the macro I have written.
° If the cell is not blank I need a check mark and then to run the macro I have written.

This should be simple and I know where to write the code for the sheet I just don't know how to trigger it. The only other question is what would happens if they select B2 through B6 or A2 through F2?

It looks like your "function needed" does the same thing for both blank and not blank cells?

What do you want done if select B2 through B6 or A2 through F2?

This would loop through each selected cell in column B and ignores selected cells in other columns.

Code:
[color=darkblue]Private[/color] [color=darkblue]Sub[/color] Worksheet_SelectionChange([color=darkblue]ByVal[/color] Target [color=darkblue]As[/color] Range)
    [color=darkblue]Dim[/color] cell [color=darkblue]As[/color] Range
    [color=darkblue]If[/color] [color=darkblue]Not[/color] Intersect(Range("B:B"), Target) [color=darkblue]Is[/color] [color=darkblue]Nothing[/color] [color=darkblue]Then[/color]
        [color=darkblue]For[/color] [color=darkblue]Each[/color] cell [color=darkblue]In[/color] Intersect(Range("B:B"), Target)
            [color=green]'do stuff here with the "cell" variable[/color]
        [color=darkblue]Next[/color] cell
    [color=darkblue]End[/color] [color=darkblue]If[/color]
End [color=darkblue]Sub[/color]
 
Upvote 0
Thank you AlphaFrog, you are right I did make a mistake. I need the cell cleared if it is not already blank. My macro will be looking to see if the cell is blank or not to decide the results of another sheet. You have given me everything I need, now all I need is a decent check mark. I found a few but I don't like any of them. I even considered the Square Root smble

FUNCTION NEEDED
When some clicks on a cell in column B
° If the cell is blank I need a check mark and then to run the macro I have written.
° If the cell is not blank I need the cell cleared and then to run the macro I have written.


Thank you again AlphaFrog!
 
Upvote 0

Forum statistics

Threads
1,215,529
Messages
6,125,344
Members
449,219
Latest member
Smiqer

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