VBA : Resize 2 Pictures in Specific Range (G13 & D13) Wtih Simultaneously

muhammad susanto

Well-known Member
Joined
Jan 8, 2013
Messages
2,102
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
hi all..

i found macro code to resize picture in Excel...
here this code :
Code:
  [TABLE]
<tbody>[TR]
[TD]Public Sub FitPic()[/TD]
[/TR]
[TR]
[TD]On Error GoTo NOT_SHAPE[/TD]
[/TR]
[TR]
[TD]Dim PicWtoHRatio As Single[/TD]
[/TR]
[TR]
[TD]Dim CellWtoHRatio As Single[/TD]
[/TR]
[TR]
[TD]With Selection[/TD]
[/TR]
[TR]
[TD]PicWtoHRatio = .Width / .Height[/TD]
[/TR]
[TR]
[TD]End With[/TD]
[/TR]
[TR]
[TD]With Selection.TopLeftCell[/TD]
[/TR]
[TR]
[TD]CellWtoHRatio = .Width / .RowHeight[/TD]
[/TR]
[TR]
[TD]End With[/TD]
[/TR]
[TR]
[TD]Select Case PicWtoHRatio / CellWtoHRatio[/TD]
[/TR]
[TR]
[TD]Case Is > 1[/TD]
[/TR]
[TR]
[TD]With Selection[/TD]
[/TR]
[TR]
[TD].Width = .TopLeftCell.Width[/TD]
[/TR]
[TR]
[TD].Height = .Width / PicWtoHRatio[/TD]
[/TR]
[TR]
[TD]End With[/TD]
[/TR]
[TR]
[TD]Case Else[/TD]
[/TR]
[TR]
[TD]With Selection[/TD]
[/TR]
[TR]
[TD].Height = .TopLeftCell.RowHeight[/TD]
[/TR]
[TR]
[TD].Width = .Height * PicWtoHRatio[/TD]
[/TR]
[TR]
[TD]End With[/TD]
[/TR]
[TR]
[TD]End Select[/TD]
[/TR]
[TR]
[TD]With Selection[/TD]
[/TR]
[TR]
[TD].Top = .TopLeftCell.Top[/TD]
[/TR]
[TR]
[TD].Left = .TopLeftCell.Left[/TD]
[/TR]
[TR]
[TD]End With[/TD]
[/TR]
[TR]
[TD]Exit Sub[/TD]
[/TR]
[TR]
[TD]NOT_SHAPE:[/TD]
[/TR]
[TR]
[TD]MsgBox "Select a picture before   running this macro."[/TD]
[/TR]
[TR]
[TD]End Sub[/TD]
[/TR]
</tbody>[/TABLE]

but have a problem, how to make/modify above code that picture after/have resized ALWAYS placing in cell D13 (pict1) and G13 (pict2) , i mean for 2 pictures resize with simultaneously in one action/click.

i hope someone would help me out.

.sst
 
Last edited:

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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