+ Reply to Thread
Results 1 to 9 of 9

Insert Picture(S) based on dropdown validation list

  1. #1
    Registered User
    Join Date
    04-21-2018
    Location
    Leeds
    MS-Off Ver
    365
    Posts
    24

    Insert Picture(S) based on dropdown validation list

    Hello everyone,

    I am new to VBA!

    Any help will be greatly appreciated.

    I have a sheet named NCR Form, in cell A9 i have a dropdown data validation list, when i pick from the data validation list pre-determined cells are automatically populated, also within this sheet are 6 picture boxes,

    What i want from these 6 picture boxes is when i pick from the Data Validation List the picture boxes automatically populate, the pictures can vary from 1 to 6.

    I can do this now using a control button with the following code that i have managed to get from this wonderful site, however I have to have 6 pictures for each one in the list

    Please Login or Register  to view this content.

    The picture boxes are named Pic_1 to Pic_6
    The pictures are located in C:\Output\ and are named NCR 00001_1, NCR 00001_2 etc

    What i desire is to get rid of the command button and have the code that will automatically populate the picture boxes using the Dropdown Data Validation List, the number of pictures will vary from 1 to 6, and have them the same size.

    Any help will be greatly appreciated!

    Thank You

    Rob
    Last edited by Rob1970; 04-23-2018 at 04:33 PM.

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,652

    Re: Insert Picture(S) based on dropdown validation list

    To install the code:
    • Right-click on the sheet tab.
    • Select View Code from the pop-up context menu.
    • Paste the code from below in the worksheet's code module.

    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Registered User
    Join Date
    04-21-2018
    Location
    Leeds
    MS-Off Ver
    365
    Posts
    24

    Re: Insert Picture(S) based on dropdown validation list

    Thank you so much Alphafrog! worked like a charm! very much appreciated and in your debt!

    Just a quick question before i mark the thread solved, the Dropdown Data Validation List has a lot inside in which the majority of them have no information at the moment (future proofed it), for example:

    NCR 00001 to NCR 00007 has info and pictures
    NCR 00008 upwards has no info until i input data and pictures in when a non conformance arises,

    When i open NCR 00008 in the Data Validation List the pictures from NCR 00007 are still there, is it possible for some code so that if an NCR number has no pictures the picture boxes are left blank instead of the last one with pictures, hope this makes sense!

    Thank you in advance!

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,652

    Re: Insert Picture(S) based on dropdown validation list

    Try something like this (not tested).

    Please Login or Register  to view this content.
    Last edited by AlphaFrog; 04-23-2018 at 01:54 PM. Reason: sp

  5. #5
    Registered User
    Join Date
    04-21-2018
    Location
    Leeds
    MS-Off Ver
    365
    Posts
    24

    Re: Insert Picture(S) based on dropdown validation list

    Hi AlphaFrog,

    Thank you for getting back!

    Works fine if the pictures are in the folder, but when you dropdown the Data Validation List to one that has no pictures the following error pops up.

    Run-time error '-2147467259 (80004005)':
    Method 'UserPicture' of Object 'Fill Format' Failed.

    Thank You.

  6. #6
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,652

    Re: Insert Picture(S) based on dropdown validation list

    This line should determine if the file exists before loading the image.
    If Len(Dir(MyPic)) Then

    When you click the Debug button on the error dialog, is this line highlighted?
    .UserPicture MyPic
    Or is this line highlighted?
    .UserPicture ""

  7. #7
    Registered User
    Join Date
    04-21-2018
    Location
    Leeds
    MS-Off Ver
    365
    Posts
    24

    Re: Insert Picture(S) based on dropdown validation list

    Hi AlphaFrog,

    When I click the Debug button the following is highlighted
    .UserPicture ""

    Thank you.
    Last edited by Rob1970; 04-23-2018 at 04:11 PM.

  8. #8
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,652

    Re: Insert Picture(S) based on dropdown validation list

    As long as you're hiding the Shapes, you really don't need that line of code. Just delete it or comment it out.

  9. #9
    Registered User
    Join Date
    04-21-2018
    Location
    Leeds
    MS-Off Ver
    365
    Posts
    24

    Re: Insert Picture(S) based on dropdown validation list

    Hi AlphaFrog,

    Works like a charm, thank you so much for you time and effort! it really is appreciated! Thank you once again.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 2
    Last Post: 12-25-2017, 09:57 PM
  2. Cross Reference (Vlookup) based on Data Validation List Dropdown
    By eguirocker3 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 06-19-2014, 05:02 PM
  3. Select Picture via Dropdown list
    By cmlucifer in forum Excel General
    Replies: 6
    Last Post: 01-21-2014, 02:51 PM
  4. Want to make a Calender with Dropdown List Events(picture) for each Day
    By pietersc in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-20-2012, 02:13 PM
  5. Replies: 0
    Last Post: 08-22-2012, 03:52 PM
  6. [SOLVED] macro: insert picture based on workbook location, not picture root path.
    By NicksDad in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-03-2012, 07:47 AM
  7. [SOLVED] Insert Picture from dropdown selection
    By Mike at Channel in forum Excel - New Users/Basics
    Replies: 21
    Last Post: 03-21-2006, 09:15 PM

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