showing picture

chobanne

Active Member
Joined
Jul 3, 2011
Messages
269
Hi all

i have 10 pictures in sheet2. i need a macro who will show appropriate picture in sheet1 bellow cell A1. if in cell A1 value is 1 then macro will show picture 1 bellow A1, if its 2 then it will show picture 2 bellow A1 etc. thank you. And i need the picture is inside range A2:F20
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
It would be easier if you places all your pictures in sheet (1) , and then used the code below, made visible only the one with the matching number in "A1" and hid all the rest.
Code:
Private [COLOR=navy]Sub[/COLOR] Worksheet_Change(ByVal Target [COLOR=navy]As[/COLOR] Range)
[COLOR=navy]Dim[/COLOR] Pic [COLOR=navy]As[/COLOR] Shape
[COLOR=navy]For[/COLOR] [COLOR=navy]Each[/COLOR] Pic [COLOR=navy]In[/COLOR] ActiveSheet.Shapes
   [COLOR=navy]If[/COLOR] Pic.Type = msoPicture [COLOR=navy]Then[/COLOR]
        [COLOR=navy]If[/COLOR] Pic.Name = "Picture " & Range("A1") [COLOR=navy]Then[/COLOR]
            Pic.Visible = True
            Pic.Top = Range("A2").Top
            Pic.Left = Range("A2").Left
        [COLOR=navy]Else[/COLOR]
            Pic.Visible = False
        [COLOR=navy]End[/COLOR] If
   [COLOR=navy]End[/COLOR] If
[COLOR=navy]Next[/COLOR] Pic
[COLOR=navy]End[/COLOR] [COLOR=navy]Sub[/COLOR]
Regards Mick
 
Upvote 0
It would be easier if you places all your pictures in sheet (1) , and then used the code below, made visible only the one with the matching number in "A1" and hid all the rest.
Code:
Private [COLOR=navy]Sub[/COLOR] Worksheet_Change(ByVal Target [COLOR=navy]As[/COLOR] Range)
[COLOR=navy]Dim[/COLOR] Pic [COLOR=navy]As[/COLOR] Shape
[COLOR=navy]For[/COLOR] [COLOR=navy]Each[/COLOR] Pic [COLOR=navy]In[/COLOR] ActiveSheet.Shapes
   [COLOR=navy]If[/COLOR] Pic.Type = msoPicture [COLOR=navy]Then[/COLOR]
        [COLOR=navy]If[/COLOR] Pic.Name = "Picture " & Range("A1") [COLOR=navy]Then[/COLOR]
            Pic.Visible = True
            Pic.Top = Range("A2").Top
            Pic.Left = Range("A2").Left
        [COLOR=navy]Else[/COLOR]
            Pic.Visible = False
        [COLOR=navy]End[/COLOR] If
   [COLOR=navy]End[/COLOR] If
[COLOR=navy]Next[/COLOR] Pic
[COLOR=navy]End[/COLOR] [COLOR=navy]Sub[/COLOR]
Regards Mick

thank you. Thats great
 
Upvote 0
Hi Mick
I tried to assign (A1) to a digital clock Seconds using
PHP:
=SECOND(Digital Clock)
but it didn't work !!

the macro to the clock is working very well
I wonder Why your macro didn't work ???
Any help 'd be very appreciated
 
Last edited:
Upvote 0
It would be easier if you places all your pictures in sheet (1) , and then used the code below, made visible only the one with the matching number in "A1" and hid all the rest.
Code:
Private [COLOR=navy]Sub[/COLOR] Worksheet_Change(ByVal Target [COLOR=navy]As[/COLOR] Range)
[COLOR=navy]Dim[/COLOR] Pic [COLOR=navy]As[/COLOR] Shape
[COLOR=navy]For[/COLOR] [COLOR=navy]Each[/COLOR] Pic [COLOR=navy]In[/COLOR] ActiveSheet.Shapes
   [COLOR=navy]If[/COLOR] Pic.Type = msoPicture [COLOR=navy]Then[/COLOR]
        [COLOR=navy]If[/COLOR] Pic.Name = "Picture " & Range("A1") [COLOR=navy]Then[/COLOR]
            Pic.Visible = True
            Pic.Top = Range("A2").Top
            Pic.Left = Range("A2").Left
        [COLOR=navy]Else[/COLOR]
            Pic.Visible = False
        [COLOR=navy]End[/COLOR] If
   [COLOR=navy]End[/COLOR] If
[COLOR=navy]Next[/COLOR] Pic
[COLOR=navy]End[/COLOR] [COLOR=navy]Sub[/COLOR]
Regards Mick


Hello mick i wonder can you make this macro to show 4 pictures depends of the value from 4 cells. macro you made was: A1 value show picture in A2. i need now beside that to manage that R1 (A20) (R21) values to show pictures in R2 (A21) (R21). Thank you for your time.
 
Upvote 0
Do the pictures that you want to show in "A2" & "R2" all have different names :- "Picture1, Picture2" etc.
 
Upvote 0
Try this:-
NB:- If you use the same number for both , then "A2" will fill with the picture.
Code:
Private [COLOR="Navy"]Sub[/COLOR] Worksheet_Change(ByVal Target [COLOR="Navy"]As[/COLOR] Range)
[COLOR="Navy"]Dim[/COLOR] Pic [COLOR="Navy"]As[/COLOR] Shape
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Pic [COLOR="Navy"]In[/COLOR] ActiveSheet.Shapes
   [COLOR="Navy"]If[/COLOR] Pic.Type = msoPicture [COLOR="Navy"]Then[/COLOR]
        [COLOR="Navy"]If[/COLOR] Pic.Name = "Picture " & Range("A1") [COLOR="Navy"]Then[/COLOR]
            Pic.Visible = True
            Pic.Top = Range("A2").Top
            Pic.Left = Range("A2").Left
        
        [COLOR="Navy"]ElseIf[/COLOR] Pic.Name = "Picture " & Range("R1") [COLOR="Navy"]Then[/COLOR]
            Pic.Visible = True
            Pic.Top = Range("R2").Top
            Pic.Left = Range("R2").Left
        [COLOR="Navy"]Else[/COLOR]
            Pic.Visible = False
        [COLOR="Navy"]End[/COLOR] If
   [COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR] Pic
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0

Forum statistics

Threads
1,224,596
Messages
6,179,807
Members
452,943
Latest member
Newbie4296

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