VBA: Cell Value = whatever the name of the shape

hrayani

Well-known Member
Joined
Jul 23, 2010
Messages
1,501
Office Version
  1. 2016
Platform
  1. Windows
Hello Friends,

I have three shapes in a worksheet with names humayun1, humayun2 & humayun3

I need a vba code which I will assign to all 3 shapes which would change the value of A1 to whatever the name of the shape is

For example: when clicked shape humayun1 then range("A1").value should be "humayun1"

Regards,

Humayun
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
How about
VBA Code:
Sub hrayani()
   Range("A1").Value = ActiveSheet.Shapes(Application.Caller).Name
End Sub
 
Upvote 0
Solution
Thanks Fluff,

That worked GREAT!

Just one more question - I apologize for not asking this in the first go

All three shapes are grouped together as "Group 4"

I want font size of all the the shapes within the the "Group 4" to be 14
and only the selected shape font size should be 16

Regards
 
Upvote 0
I've never worked with grouped shapes, so have no idea how to do that.
Hopefully someone else will step in.
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0
Hi Fluff,

With a bit of searching on the net & tweaking, I came up with this which serves the additional purpose

The reason for posting the whole code is that it might be of any sort of help for someone

VBA Code:
Sub testing()

Dim sp As Object
Dim ActiveShape As Shape

ButtonName = Application.Caller
Set ActiveShape = ActiveSheet.Shapes(ButtonName)

Set sp0 = ActiveSheet.DrawingObjects("Group 4")

    With sp0.Font
        .Bold = False
        .Size = 9
        .ColorIndex = 16
    End With

ActiveShape.Select
    With Selection.Font
        .Bold = True
        .Size = 12
        .ColorIndex = 1
        Range("C11").Select
    End With

Range("A1").Value = ActiveSheet.Shapes(Application.Caller).Name

End Sub
 
Upvote 0
Glad you sorted it & thanks for letting us know.
 
Upvote 0

Forum statistics

Threads
1,215,692
Messages
6,126,227
Members
449,303
Latest member
grantrob

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