Get Name Box value of shape in current region

PressEscape

New Member
Joined
May 2, 2024
Messages
22
Office Version
  1. 2021
Platform
  1. Windows
I wish to get the the name box value of the picture within a selected region with VBA
1718571431395.png

I can navigate and select the region. What's the trick to get the name box value (picture 27) and assign it to a variable?
1718571551542.png
 
A variation of Jaafar's suggestion in case the CurrentRegion from TopLeftCell does not work (no direct adjacent cell with a value).
Code:
Sub Maybe_So()
Dim shp As Shape
    For Each shp In ActiveSheet.Shapes
    If shp.Type = msoPicture Then shp.Name = shp.TopLeftCell.Offset(, -2).CurrentRegion.Cells(2, 2).Value
Next shp
End Sub
This needs the first column of the area to be all values
 
Last edited:
Upvote 0

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
How do we add a error check if cell 2,2 is empty?

I've tried
"if shp is nothing then"
but how do I move to the next shape?


Sub Maybe_So()
Dim shp As Shape
For Each shp In ActiveSheet.Shapes
If shp.Type = msoPicture Then shp.Name = shp.TopLeftCell.Offset(, -2).CurrentRegion.Cells(2, 2).Value
Next shp
End Sub
 
Upvote 0
You are comparing a range, cell 2, 2 and an object, shp. That will not work.
Code:
 If Len(cells(2, 2))<> 0 Then

To stay with what you have in Post #33
Code:
For Each shp In ActiveSheet.Shapes
    If shp.Type = msoPicture And Len(shp.TopLeftCell.Offset(, -2).CurrentRegion.Cells(2, 2)) <> 0 Then shp.Name = shp.TopLeftCell.Offset(, -2).CurrentRegion.Cells(2, 2).Value
Next shp
 
Last edited:
Upvote 0
I've got the code working
how can I then set shp.name to something like "Nothing" for every empty cell at (2,2)
 
Upvote 0
Re: "how can I then set shp.name to something like "Nothing" for every empty cell at (2,2)"
Please elaborate the thought behind this.
 
Upvote 0

Forum statistics

Threads
1,221,805
Messages
6,162,074
Members
451,738
Latest member
gaseremad

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