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
3,194
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
 

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.
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.
 
Upvote 0
Solution
Wow,
that is amazing you have just saved me a about 3 days of codes lol :)
Thanks
Tony
 
Upvote 0

Forum statistics

Threads
1,214,661
Messages
6,120,792
Members
448,994
Latest member
rohitsomani

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