Sorting PICTURES once they have been imported into a cell

GaryJ09

New Member
Joined
Jun 11, 2009
Messages
29
Hello, I have inserted pictures into my worksheet with this code:

Code:
Sub InsertPicture()
Dim sPicture As String, pic As Picture
 
sPicture = Application.GetOpenFilename _
    ("Pictures (*.gif; *.jpg; *.bmp; *.tif), *.gif; *.jpg; *.bmp; *.tif", _
     , "Select Picture to Import")
 
If sPicture = "False" Then Exit Sub
 
Set pic = ActiveSheet.Pictures.Insert(sPicture)
With pic
    .ShapeRange.LockAspectRatio = msoFalse
    .Height = ActiveCell.Height
    .Width = ActiveCell.Width
    .Top = ActiveCell.Top
    .Left = ActiveCell.Left
    .Placement = xlMoveAndSize
    .ShapeRange.LockAspectRatio = msoTrue
' etc.
End With
 
Set pic = Nothing
 
End Sub

I am having a problem when I try to sort the columns next to the pictures. Please take a look at the picture below:

Sampledatabase.jpg


If I sort the Item Number column, the pictures do not move and stay in their respective cells. Is there any way to change this? Thanks.
 
Couple of things:
I did not have a picture for one of the item numbers, br001
missingbr001pic.jpg


So after I ran the macro, it messed up the association between picture, item number, and description, as well as rest of the worksheet. Please look at row 7 in the picture below:
afterrunningmacrobr001isdeleted.jpg

This dissociation subsequently occurred throughout the worksheet.

messedupsort.jpg


Also, is there a way to size the pictures according to cell size?

Thank you.
 
Upvote 0

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
One thing I noticed is that if I have pictures in a folder which I do not have descriptions for, the macro straight dumps the pictures according to alphabetical order and messes up association with all the pictures.

What I need is:
1) if there is no picture for a particular item number in the worksheet, the macro leave that row alone and not attach a picture with it.
2) if there is a picture in the folder for which there is no item number in the worksheet, the macro should not insert that picture into the worksheet

I think the best way would be, is if you can have the macro look at the item number (in the worksheet) and then see if that item number corresponds to a file in the folder and then insert that file.

Thanks.
 
Upvote 0

Forum statistics

Threads
1,215,869
Messages
6,127,421
Members
449,382
Latest member
DonnaRisso

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