macros to insert picture in active cell, but picture appears more shifted out of position the higher the row

needhelp9009

New Member
Joined
Mar 30, 2021
Messages
7
Office Version
  1. 365
Platform
  1. Windows
I am using a macros to insert pictures into the active cell.
i.e. click B3, run macros and choose picture from the file. this works well in row 3. However, as I continue adding pictures going down the rows. example B90, the picture appears shifted out of the box..
Capture6.JPG
Capture7.JPG


This is my code:
VBA Code:
Sub test()
Dim myPic As String, Pic As Shape, Rng As Range
Dim a As Double, shp As Shape, x As Long, j As Long, jj As Long


    For Each shp In ActiveSheet.Shapes
        If Left(shp.Name, 7) = "Picture" Then x = x + 1
    Next shp
   
myPic = Application.GetOpenFilename( _
    FileFilter:="Images (*.jpg;*.gif;*.png),*.jpg;*.gif;*.png", _
        Title:="Please select an image...")
    If myPic = "False" Then Exit Sub

Set Pic = Application.ActiveSheet.Shapes.AddPicture(myPic, False, True, 0, 0, -1, -1)

j = ActiveCell.Row
jj = ActiveCell.Column


With Pic
    .Name = "Picture" & x + 1
    .LockAspectRatio = False
    .Left = Cells(j, jj).Left
    .Top = Cells(j, jj).Top - (j * 1 / 100)
    .Height = ActiveCell.Height
    .Width = ActiveCell.Width
   
End With

End Sub
 
Last edited by a moderator:

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.

jolivanes

Well-known Member
Joined
Sep 5, 2004
Messages
1,841
Office Version
  1. 2013
  2. 2007
Platform
  1. Windows
When you right click on the picture in your sheet that is not properly lined up, you don't get the same as the top picture?
If you do and click on "Size and Properties" and at the pop up at top select "Size", do you see "Rotation"?
If you do, what does it show there?
 

Attachments

  • Size and Properties.JPG
    Size and Properties.JPG
    115.7 KB · Views: 2

Forum statistics

Threads
1,147,482
Messages
5,741,404
Members
423,657
Latest member
Medrok2021

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
Top