Hello friends,
I've created a macro button that will change the inserted image properties to 'Move and size with cells' and to adjust the size to fit within the cell. I found this code online and adjusted the height for my row height...
This works well, however I need help to make two code adjustments:
Many thanks
I've created a macro button that will change the inserted image properties to 'Move and size with cells' and to adjust the size to fit within the cell. I found this code online and adjusted the height for my row height...
Code:
Dim xPic As Picture
For Each xPic In ActiveSheet.Pictures
xPic.Placement = xlMoveAndSize
xPic.ShapeRange.LockAspectRatio = msoTrue
xPic.ShapeRange.Height = 85
Next
This works well, however I need help to make two code adjustments:
- Change from 'For each xPic in ActiveSheet' to only run on the image that is currently selected. I don't want it to resize all images that are in the active sheet, each time the button is pushed.
- Resize the image depending on the aspect ratio, so that it will always fit within the cells dimensions (Desired cell dimensions are Height =85, Width = 230)
- eg 1. Image A is 125h x 90w (ie Portrait aspect ratio)
- As it's portrait, I want the macro to resize the image so the height is 85, and the width adjusts accordingly, maintaining aspect ratio
- eg 2. Image B is 50h x 300w (ie Landscape aspect ratio)
- As it's landscape, I want the macro to resize image so the width is 230, and the height adjusts accordingly, maintaining aspect ratio
- eg 1. Image A is 125h x 90w (ie Portrait aspect ratio)
Many thanks