• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Image mapping

Dinesh@Dinu

New Member
Hi All,

Can you please help to map the image from the Source sheet to the destination sheet with reference to the product name?
 

Attachments

  • Image maping.xlsx
    177.8 KB · Views: 9
Last edited by a moderator:
Hi, according to your attachment - as it is - a worksheet event VBA procedure to paste only to the Sheet2 (Target) worksheet module :​
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
        Dim P&, Rc As Range, oPic As Picture
        Set Target = Intersect(UsedRange.Columns(1), Target):  If Target Is Nothing Then Exit Sub
    With New Collection
        For P = 1 To Sheet1.Pictures.Count:  .Add P, Sheet1.Pictures(P).TopLeftCell.Cells(1, 0).Text:  Next
    For Each Rc In Target
    For Each oPic In Pictures
          If oPic.TopLeftCell.Address = Rc(1, 2).Address Then oPic.Delete: Exit For
    Next
        P = 0
        On Error Resume Next
        P = .Item(Rc.Text)
        On Error GoTo 0
     If P Then
        Sheet1.Pictures(P).Copy
          With Pictures.Paste
                Shapes(.Name).LockAspectRatio = -1
                    If .Height > Rc.Height - 4 Then .Height = Rc.Height - 4
                    If .Width > Rc(1, 2).Width - 4 Then .Width = Rc(1, 2).Width - 4
                       .Left = Rc(1, 2).Left + (Rc(1, 2).Width - .Width) / 2
                       .Top = Rc.Top + (Rc.Height - .Height) / 2
          End With
     End If
    Next
    End With
        Set oPic = Nothing
End Sub
Do you like it ? So thanks to click on bottom right Like !​
 
Hi Mark,

Thank you for the code. Finding difficulty in running same. As i am new to the macros, i m unable to debug the issue. Can you please run the module in the added attachment and fix the issue to help me out. Ihave spend much time without success, If you try it will be of great help.
 

Attachments

  • Image maping.xlsm
    182.9 KB · Views: 2
You felt in the bad readers trap !​
So delete first the very useless Module1.​
Then back to post #2, just well read and apply at least the direction to follow …​
Explain what you still do not undestand if necessary.​
 
Hi Marc,

As per Post #2 directions, have pasted the given code in Sheet2 (Target). Upon running the command below Macro name window pops up. Advise next steps to follow.

84242
 
Back
Top