Edit a VB to Vlookup a picture

CraigFord

New Member
Joined
Sep 5, 2011
Messages
39
i have used the VB code in the link below

http://www.mcgimpsey.com/excel/lookuppics.html


Code:
Private Sub Worksheet_Calculate()
        Dim oPic As Picture
        Me.Pictures.Visible = False
        With Range("F1")
            For Each oPic In Me.Pictures
                If oPic.Name = .Text Then
                    oPic.Visible = True
                    oPic.Top = .Top
                    oPic.Left = .Left
                    Exit For
                End If
            Next oPic
        End With
    End Sub
the problem i have is the code makes all pictures on the sheet hidden, however there are some pictures on the skeet that need to be shown all of the time, is there a way i can stop some pics being hidden?
 
Enter Picture 4 in F1 and Picture 5 in F5.

Really Sorry, i think i have confused the post by asking multiple questions,

i assume that your post relates to my problem witht the dissapearing images, im not too concerned about the pictures i want shown dissapearing (as i can get round this using the pricures in a header which works well), my bigger problem is that i have made this work in a blank workbook however once i have done the exact same thing in the purchase order i have created it only shows the text not the image.
 
Upvote 0
ok to give an update

i have now fixed the hidden pictures and got the VB working

the last thing i need is for the bottom right of the image to be inline with the bottom right of the cell

currently the picture is alligned with the top left

i assume this has something to do with the highlightd element of code below

Code:
Option Explicit

    Private Sub Worksheet_Calculate()
        Dim oPic As Picture
        Me.Pictures.Visible = True
        With Range("G51")
            For Each oPic In Me.Pictures
                If oPic.Name = .Text Then
                    oPic.Visible = True
                    [COLOR=Red]oPic.Top = .Top
                    oPic.Left = .Left[/COLOR]
                    Exit For
                End If
            Next oPic
        End With
        With Range("G54")
            For Each oPic In Me.Pictures
                If oPic.Name = .Text Then
                    oPic.Visible = True
                    [COLOR=Red]oPic.Top = .Top
                    oPic.Left = .Left[/COLOR]
                    Exit For
                End If
            Next oPic
        End With
    End Sub
 
Upvote 0
Indeed it does:

Rich (BB code):
Private Sub Worksheet_Calculate()
    Dim oPic As Picture
    Me.Pictures.Visible = True
    With Range("G51")
        For Each oPic In Me.Pictures
            If oPic.Name = .Text Then
                oPic.Visible = True
                oPic.Top = .Top - (oPic.Height - .Height)
                oPic.Left = .Left - (oPic.Width - .Width)
                Exit For
            End If
        Next oPic
    End With
    With Range("G54")
        For Each oPic In Me.Pictures
            If oPic.Name = .Text Then
                oPic.Visible = True
                oPic.Top = .Top - (oPic.Height - .Height)
                oPic.Left = .Left - (oPic.Width - .Width)
                Exit For
            End If
        Next oPic
    End With
End Sub
 
Upvote 0
Indeed it does:

Rich (BB code):
Private Sub Worksheet_Calculate()
    Dim oPic As Picture
    Me.Pictures.Visible = True
    With Range("G51")
        For Each oPic In Me.Pictures
            If oPic.Name = .Text Then
                oPic.Visible = True
                oPic.Top = .Top - (oPic.Height - .Height)
                oPic.Left = .Left - (oPic.Width - .Width)
                Exit For
            End If
        Next oPic
    End With
    With Range("G54")
        For Each oPic In Me.Pictures
            If oPic.Name = .Text Then
                oPic.Visible = True
                oPic.Top = .Top - (oPic.Height - .Height)
                oPic.Left = .Left - (oPic.Width - .Width)
                Exit For
            End If
        Next oPic
    End With
End Sub

do i need to replace

oPic.Top = .Top
with
oPic.Height = .Height
 
Upvote 0

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