VBA To Resize image

Theglyde

New Member
Joined
May 29, 2020
Messages
34
Office Version
  1. 365
Platform
  1. Windows
Hi guys I tried multiple image resize codes and none work for me. I feel it should be simple but I will explain what I am trying to do


I have an image already inserted on my excel sheet

I want to be able to click the image and then click button that will resize not keeping ratio to 2.28”Height
3.77” width
and then put in Cell D9 which is already sized for that…

Sorry I do not have any code since none I tried work and did not want to confuse anyone
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
roughly this
VBA Code:
Sub MyShape()
     Set sh = ActiveSheet
     Set c = sh.Range("D9")
     With sh.Shapes("myshape")
          .Left = c.Left
          .Top = c.Top
          .Width = c.Offset(, 1).Left - c.Left - 0.1            'adapt width to the width of the cell
          .Height = c.Offset(1).Top - c.Top - 0.1
     End With
     
End Sub
 
Upvote 0
i didn't know the name of your shape, so change that with the real name of your shape.
you find that name in the top left corner of excel just under the ribbon, if you select that shape.
 
Upvote 0
Still not working, I do lots of VbA and this is baffling me ? The picture is never the same picture or name

I assume some VbA must work.

Literally just what ever picture I click before hitting the button to get it to change size and then go in specific Cell

I assumed it would be with Active.shape
and Range but I can’t get it to work
 
Upvote 0
VBA Code:
Sub MyShape()
     Set sh = ActiveSheet
     Set c = sh.Range("D9")

     With Selection.ShapeRange 'your actual selected shape
          .Left = c.Left
          .Top = c.Top
          .Width = c.Offset(, 1).Left - c.Left - 0.1            'adapt width to the width of the cell
          .Height = c.Offset(1).Top - c.Top - 0.1
     End With

End Sub
an interesting property is "LockAspectRatio" if you want or don't want the width and height locked.
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,684
Members
448,977
Latest member
dbonilla0331

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