+ Reply to Thread
Results 1 to 12 of 12

Macro Image Help

Hybrid View

slamups21 Macro Image Help 08-02-2011, 04:49 PM
Chance2 Re: Macro Image Help 08-02-2011, 07:15 PM
slamups21 Re: Macro Image Help 08-04-2011, 12:30 AM
slamups21 Re: Macro Image Help 08-04-2011, 10:18 AM
shg Re: Macro Image Help 08-04-2011, 11:06 AM
royUK Re: Macro Image Help 08-04-2011, 02:22 AM
Chance2 Re: Macro Image Help 08-04-2011, 01:22 PM
slamups21 Re: Macro Image Help 08-04-2011, 02:23 PM
Chance2 Re: Macro Image Help 08-04-2011, 03:09 PM
slamups21 Re: Macro Image Help 08-04-2011, 03:47 PM
Chance2 Re: Macro Image Help 08-04-2011, 07:04 PM
slamups21 Re: Macro Image Help 08-05-2011, 01:42 PM
  1. #1
    Registered User
    Join Date
    07-13-2011
    Location
    Boston, Massachusetts
    MS-Off Ver
    Excel 2007
    Posts
    12

    Macro Image Help

    I posted this a week or so ago but I havent heard back in a while after some intitial good feedback so I thought I would re-post.

    General Idea: I want Excel to call up an image to match a series of cells I have created. The logic is this: a user selects from 6 Yes/No fields, and depending on their combination, I want a specific image that is in a different workbook to appear.For example a chain of Yes/Yes/No should bring up a different image than Yes/No/Yes. The list of combinations will not be including duplicates, so 2+3 and 3+2 would bring up the same image.

    The following code and workbook is how far I have gotten, and there remain two problems I would like to fix:

    1) The worksheet only reacts and pastes a picture once the user changes cell C8. Can we manipulate this so each of the dropdown cells C4-C8, will paste an appropriate picture if changed?
    2) Each click of the C8 dropdown cell pastes the image on top of already pasted images. It gets in the way of the worksheet, it would be best if one click made the picture appear and another would not make a change unless it is to bring up another picture


     
    
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.Count > 1 Then Exit Sub
    If Not Intersect(Target, Range("C8")) Is Nothing Then
    
        If Range("C8").Value = "Yes" And Range("C7").Value = "Yes" And Range("C6").Value = "Yes" And _
        Range("C5").Value = "Yes" And Range("C4").Value = "Yes" Then
        
        Application.EnableEvents = False
            Sheets(2).Shapes("Picture 1").Copy
                Sheets(1).Range("e4").Select
                    ActiveSheet.Paste
                        
        ElseIf Range("C8").Value = "Yes" And Range("C7").Value = "Yes" And Range("C6").Value = "Yes" And _
        Range("C5").Value = "Yes" And Range("C4").Value = "No" Then
        Application.EnableEvents = False
            Sheets(2).Shapes("Picture 2").Copy
                Sheets(1).Range("D4").Select
                    ActiveSheet.Paste
                        
        ElseIf Range("C8").Value = "Yes" And Range("C7").Value = "Yes" And Range("C6").Value = "Yes" And _
        Range("C5").Value = "No" And Range("C4").Value = "No" Then
        Application.EnableEvents = False
            Sheets(2).Shapes("Picture 3").Copy
                Sheets(1).Range("D4").Select
                    ActiveSheet.Paste
                    
        ElseIf Range("C8").Value = "Yes" And Range("C7").Value = "Yes" And Range("C6").Value = "No" And _
        Range("C5").Value = "No" And Range("C4").Value = "No" Then
        Application.EnableEvents = False
            Sheets(2).Shapes("Picture 4").Copy
                Sheets(1).Range("D4").Select
                    ActiveSheet.Paste
                    
        ElseIf Range("C8").Value = "Yes" And Range("C7").Value = "No" And Range("C6").Value = "No" And _
        Range("C5").Value = "No" And Range("C4").Value = "No" Then
        Application.EnableEvents = False
            Sheets(2).Shapes("Picture 5").Copy
                Sheets(1).Range("D4").Select
                    ActiveSheet.Paste
                    
        ElseIf Range("C8").Value = "No" And Range("C7").Value = "No" And Range("C6").Value = "No" And _
        Range("C5").Value = "No" And Range("C4").Value = "No" Then
        Application.EnableEvents = False
            Sheets(2).Shapes("Picture 6").Copy
                Sheets(1).Range("D4").Select
                    ActiveSheet.Paste
        ElseIf Range("C8").Value = vbNullString Then
        Exit Sub
        Else
        MsgBox "You need to add more conditions"
         
       
        
        End If
        
    Else
    Exit Sub
    End If
    
    Application.EnableEvents = True
        
    End Sub
    Attached Files Attached Files
    Last edited by slamups21; 08-05-2011 at 01:44 PM.

  2. #2
    Forum Contributor
    Join Date
    04-01-2009
    Location
    Irvine, CA
    MS-Off Ver
    Excel 2010
    Posts
    280

    Re: Macro Image Help

    Is it important to use code for this?

    This can be done with named ranges and the CHOOSE command (as one method).
    I aligned your images with cells so I could reference them, then I copied a cell (does not matter which) and pasted as a picture link (under the paste menu). I then made a named range called MyPic and added my choose formula (you may want to use something else depending on your final product). Finally I changed the link (in the address bar) of my pasted picture link (from step one) to the MyPic reference...

    Note: The paste as picture link is a little more difficult to find in xl 2003, but it is there (I think you need to shift while selecting the Edit menu)
    Attached Files Attached Files

  3. #3
    Registered User
    Join Date
    07-13-2011
    Location
    Boston, Massachusetts
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: Macro Image Help

    wow this looks perfect! I have no experience at all with the choose command and am finding it a little difficult to backtrack from your example sheet but I hope I will figure it out. How does it know what combination of Yes/No to use with which image? This looks brilliant I just gotta figure it out im glad its possible without code

  4. #4
    Registered User
    Join Date
    07-13-2011
    Location
    Boston, Massachusetts
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: Macro Image Help

    The answer you provided was good, but Im finding a problem I cant get around. The choose function is spitting out a picture based on the number of "Yes" the user selects. This presents a problem,however, since I need a different image for different combinations, even if they have the same number of Yes. For example if cell 1 and 2 are Yes, or 1 and 3 are Yes, I would want two different pictures, but the function you provided would yield the same pic for both. Is there a way to do a nested if function within the choose?

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Macro Image Help

    Perhaps ...

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        Dim iCase       As Long
    
        If Target.Address = "$C$8" Then
            On Error GoTo Oops
            Application.EnableEvents = False
            iCase = [sumproduct((C4:C8 = "yes") * {16,8,4,2,1})]
    
            ' iCase = 0 to 31, depending on the combinations of Yes appearing in C4:C8
            Select Case iCase
                Case 0
                    Worksheets(2).Shapes("Picture 1").Copy
                    Worksheets(1).Range("E4").PasteSpecial
                Case 1
    
                Case 2
    
                    '...
    
                Case 31
            End Select
        End If
    Oops:
        Application.EnableEvents = True
    End Sub
    Entia non sunt multiplicanda sine necessitate

  6. #6
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Macro Image Help

    You should continue in your original post if it hasn't been solved
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  7. #7
    Forum Contributor
    Join Date
    04-01-2009
    Location
    Irvine, CA
    MS-Off Ver
    Excel 2010
    Posts
    280

    Re: Macro Image Help

    Still avoiding code, you will need a table of combinations and picture locations.
    I have added the table and modified MyPic. I used another name for the combinations (MyChoice)...
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    07-13-2011
    Location
    Boston, Massachusetts
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: Macro Image Help

    This worksheet looks much better, do you mind going a little more detailed as to how I would re-create this with my actual data? I am fine up until the point of creating the MyPic but I dont know where the MyChoice comes in and how that works

  9. #9
    Forum Contributor
    Join Date
    04-01-2009
    Location
    Irvine, CA
    MS-Off Ver
    Excel 2010
    Posts
    280

    Re: Macro Image Help

    MyChoice is just a series of concantinated IF statements to get your unique combinations.

    Each IF is just checking for Yes and placing a number or null based upon the results.

  10. #10
    Registered User
    Join Date
    07-13-2011
    Location
    Boston, Massachusetts
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: Macro Image Help

    Ok cool, I guess the part still confusing is how are MyChoice and MyPic linked? Do I assign MyChoice to a specific cell?

  11. #11
    Forum Contributor
    Join Date
    04-01-2009
    Location
    Irvine, CA
    MS-Off Ver
    Excel 2010
    Posts
    280

    Re: Macro Image Help

    MyChoice returns a combination from the questions from Testing (C4 - C8).
    C4 = 1, C5 = 2, C6 = 3 and so on (if you have more than 5 in your final sheet).
    Examples:
    C4 = Yes and C5 = Yes and C6 = No then MyChoice = 12
    C4 = Yes and C5 = No and Yes = No then MyChoice = 13
    C4 = No and C5 = Yes and Yes = No then MyChoice = 23

    MyPic uses MyChoice (Combination column E) to find the location of the picture (Range column F) on Sheet1. The "Range" represents the cells behind the pictures, so you can have as many combinations as pictures. in this case I just randomly assigned combinations to pictures.

  12. #12
    Registered User
    Join Date
    07-13-2011
    Location
    Boston, Massachusetts
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: Macro Image Help

    Thanks so much for all the help I have it up and running now, it is exactly what I was looking for!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1