Automatically change shape size based on values in a cell

jrv326s

New Member
Joined
Mar 9, 2011
Messages
3
Hi everyone,

I've been wrestling with what is probably a simple problem. I have a map of the US on one worksheet with shapes (circles) over locations where our company has resources. I've put in a button on that sheet that toggles the shape on or off using the .visible = true or .visible = false properties. This button also has a caption that toggles as well. However, I also want to dictate the size of those shapes based on values entered in another worksheet in the same workbook. I've tried and just can't get it to work. Here's the kind of code I am using to toggle the visibility. I'd like to insert code into this event that will also adjust the circle size based on value in a cell. Thanks!

Private Sub CommandButton5_Click()
If CommandButton5.Caption = "Hide" Then
CommandButton5.Caption = "Show"
ActiveSheet.Shapes("Oval 1_LosAngeles").Visible = False
Else
If CommandButton5.Caption = "Show" Then
CommandButton5.Caption = "Hide"
ActiveSheet.Shapes("Oval 1_LosAngeles").Visible = True
End If
End If
End Sub
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Hi
Welcome to the board

For ex., using the value in A1, try:

Code:
Private Sub CommandButton5_Click()

If CommandButton5.Caption = "Hide" Then
    CommandButton5.Caption = "Show"
    ActiveSheet.Shapes("Oval 1_LosAngeles").Visible = False
ElseIf CommandButton5.Caption = "Show" Then
    CommandButton5.Caption = "Hide"
    With ActiveSheet.Shapes("Oval 1_LosAngeles")
        .Visible = True
        .Width = Range("A1").Value
        .Height = Range("A1").Value
    End With
End If
End Sub
 
Upvote 0
Thank you so much PCG! The mechanism is working, although it is not what I would expect. I was thinking the value in the cell would effectively change the size property of the shape. For example, I'd think that if I put the value "1" in the cell "A1" then the value "1" would be inserted in the height and width of the "Size and Properties" for that shape. It does not. It's like those properties of the shape don't change and the value in "A1" is just a multiplier.

At any rate, I can work with this and I really appreciate the helping hand.

God bless.

Joshua
 
Upvote 0
The mechanism is working, although it is not what I would expect. I was thinking the value in the cell would effectively change the size property of the shape. For example, I'd think that if I put the value "1" in the cell "A1" then the value "1" would be inserted in the height and width of the "Size and Properties" for that shape. It does not. It's like those properties of the shape don't change and the value in "A1" is just a multiplier.

Hi Joshua

I'm glad it helped.

The value in A1 is indeed the value that will be in the height and width properties in the shape. If you check the help for those properties you'll see that these properties are measured in points.

What you see in the "Size and Properties" form is the values converted to whatever the measurement units you use in your country. For ex. if in your regional settings you use centimeters, then if you set A1 to 28 you'll get approximately 1 cm.
 
Upvote 0
Working like a charm...except...

The use case is that these are circles on a US map showing how many resources we have in a given location. When I increase the size, the shape increases with the top left of the shape staying in the original position. This effectively moves the center of my circle off it's original location, defeating my purpose. I need to somehow either lock the center of the shape or increment movement of the shape up and to the left to compensate for the increased Height and Width. Clear as mud? :)
 
Upvote 0
Hi

In that case, in addition to the values of the .Width and the .Height properties, set also the values of the properties .Top and .Left. This allows you to control both the size and the position of the shape.
 
Upvote 0
Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
I am all so struggling with this problem, I am really new with Excel and I need to create a model for a water tank according to a specific value in a cell! now I have tried your method but I just can't seem to make it work.<o:p></o:p>
All it needs to do is resize a Rectangle (but stay positioned in the same place ,only resize upwards to a max ) when I change the value in the specific cell!<o:p></o:p>
Can you please help me!!!<o:p></o:p>
<o:p></o:p>
Regards Adriaan<o:p></o:p>
:help::banghead:
 
Upvote 0
I know that there are probably different ways to do this, but maybe you can do something like this;

VB:

With Cells
.WrapText = True
.EntireColumn.AutoFit
.EntireRow.AutoFit
End With

Is there a specific height or width that you want? How many columns will you be using? The excel formulas might differ a bit based on your size and column amount.
 
Upvote 0
Hi, i am doing similar exercise. i am wondering if i have to show 100rectangles with respect to 100 cell data, then do i have to enter the vba code for each rectangle ?

If anyone has any shortcut, then it would help a lot.

Thanks
 
Upvote 0

Forum statistics

Threads
1,224,531
Messages
6,179,379
Members
452,907
Latest member
Roland Deschain

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