Identifying the shape i clicked

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,194
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi everyone,
So heres the situation,
I have two shapes
one to called Hide12
the other called Unhide12

i want a macro to identify the shapes name simply by the fact i clicked it,
then use a macro that says.
clicked shape hide,
other shape unhide

OK let me make this clearer,
on my page all my shapes are called either "Hide" or "Unhide" followed by a number for example Hide1 matches Unhide1 etc
i want a macro that i can assinge to all these shapes that says this

Get the Clicked shapes name,
if name starts with "Un" the "Hide" + (number on end of name) visible "Unhide" hidden

so i hide one shape show the other
can this be done?

thanks

Tony
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Why not just use one shape & change the name from Hide to Unhhide & vice versa every time you click it?
 
Upvote 0
I can do the rest so actually thinking about it i just need the bit i'm stuck on

which is if the shapes name is "Unhide1" how do i get the "1" out
 
Upvote 0
You can use Activesheet.Shapes(Application.Caller) to get the shape that was clicked.
 
Upvote 0
Ok we are getting somewhere thank you everyone.
Why not just use one shape & change the name from Hide to Unhhide & vice versa every time you click it?
There two different shapes! lol
Yes I know that, but why? It would be easier to have one shape that acts as a toggle & you can change the name every time it's clicked.
No you are missing the point, they are two DIFFERENT shapes as in one is a square one is a triangle, and it needs to be this way for my design

so if i can use
You can use Activesheet.Shapes(Application.Caller) to get the shape that was clicked.
to get the shape, how can i do this?

if Activesheet.Shapes(Application.Caller first two letters are "Un" then take the number from the end and unhide "Hide" + nunber on the end???
 
Upvote 0
How about
VBA Code:
Sub tonywatson()
   Dim Shp As Shape
   
   Set Shp = ActiveSheet.Shapes(Application.Caller)
   If Left(Shp.name, 2) = "Un" Then
      ActiveSheet.Shapes(Mid(Shp.name, 3)).Visible = True
   Else
      ActiveSheet.Shapes("Un" & Shp.name).Visible = True
   End If
End Sub
 
Upvote 0
You probably want a shp.Visible = False too.
 
Upvote 0

Forum statistics

Threads
1,214,981
Messages
6,122,566
Members
449,089
Latest member
Motoracer88

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