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?
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
That code hides all the pictures except the one whose name is in F1. What are the names of the pictures that you don't want to hide?
 
Upvote 0
Try:

Code:
Private Sub Worksheet_Calculate()
    Dim oPic As Picture
    Me.Pictures.Visible = False
    For Each oPic In Me.Pictures
        If oPic.Name = "Picture 4" Or oPic.Name = "Picture 5" Then
            oPic.Visible = True
        End If
    Next oPic
End Sub

Sorry, I don't know what you mean by "im trying to do this twice on the same sheet the lookup call for the second command is F5".
 
Upvote 0
Try:

Code:
Private Sub Worksheet_Calculate()
    Dim oPic As Picture
    Me.Pictures.Visible = False
    For Each oPic In Me.Pictures
        If oPic.Name = "Picture 4" Or oPic.Name = "Picture 5" Then
            oPic.Visible = True
        End If
    Next oPic
End Sub
Sorry, I don't know what you mean by "im trying to do this twice on the same sheet the lookup call for the second command is F5".

dont worry i have sussed the second part with the code below

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
        With Range("F5")
            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

how does the code you have written above fit into my current code? are you able to repost the entire code?
 
Upvote 0
i got the code working perfectly in a blank workbook now i have added it to the workbook i want to use it wont work!!

am i able to upload the document for smebody to assist
 
Upvote 0

Forum statistics

Threads
1,222,180
Messages
6,164,419
Members
451,894
Latest member
480BOY

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