Can amacro ref the cell under the shape clicked so my macro can run on lots of rows

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
2,717
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi Everyone,
I have this code that when run simply adds in to cell "H15" the words "Section locked" or "Section Unlocked" and hides/unhides one of two shapes "ulock1" or "Lock1"
now this works great but i want to use it on my entire sheet
so instead of just H15, it will work for H20, H50 Ect.

how this can happenis like this,
i have shapes in every cell i want the macro to run on,
so if the macro could somehow identify what the cell under the shape was we could use this to adjust the refences

so is theeere a way to say
instead of CLL = "H15"
CLL = the cell under the shaped clicked?
here my code
Thanks
Tony

VBA Code:
Sub Lock1()
Application.EnableEvents = False
Call AA_unProtect
CLL = "H15"
Unlocked = "ulock1"
Locked = "Lock1"
If ActiveSheet.Range(CLL).Value = "Section locked" Then
ActiveSheet.Shapes(Unlocked).Visible = msoFalse
ActiveSheet.Shapes(Locked).Visible = msoTrue
 ActiveSheet.Range(CLL).Value = "Section Unlocked"
 
Else
ActiveSheet.Shapes(Unlocked).Visible = msoTrue
ActiveSheet.Shapes(Locked).Visible = msoFalse
 ActiveSheet.Range(CLL).Value = "Section locked"
End If
AA_Protect
Application.EnableEvents = True

End Sub
 

Some videos you may like

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,238
Office Version
  1. 365
Platform
  1. Windows
You could use
VBA Code:
CLL = ActiveSheet.Shapes(Application.Caller).TopLeftCell.Address
This will reference the cell under the top left corner of the shape.
 
Solution

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
2,717
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Wow,
that is amazing you have just saved me a about 3 days of codes lol :)
Thanks
Tony
 

Watch MrExcel Video

Forum statistics

Threads
1,126,966
Messages
5,621,874
Members
415,862
Latest member
nascaline

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
Top