Results 1 to 6 of 6

Thread: VB- ComboBox

  1. #1

    Thread Starter
    Hyperactive Member Greyskull's Avatar
    Join Date
    Dec 2003
    Location
    somewhere in England
    Posts
    382

    VB- ComboBox

    Code:
    Sub Dropdown1_Change()
    Dim s As String 
    Select Case Cells(1, 1).Value 
    Case 1 
        s = "C:\1.jpg" 
    Case 2 
        s = "C:\2.jpg" 
    End Select 
    ActiveSheet.Pictures.Insert s
    End Sub
    Can anyone make this code any simpler for having a ComboBox with pictures.

    Thanx,

    Greyskull

  2. #2
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    Well either of these are simpler in as much as less coding but I'd go with what you've got there to be honest - it'd perform just as well ...
    VB Code:
    1. Sub Dropdown1_Change()
    2.     Select Case Cells(1, 1).Value
    3.     Case 1
    4.         ActiveSheet.Pictures.Insert = "C:\1.jpg"
    5.     Case 2
    6.         ActiveSheet.Pictures.Insert = "C:\2.jpg"
    7.     End Select
    8. End Sub

    or

    VB Code:
    1. Sub Dropdown1_Change()
    2.     IF (Cells(1, 1).Value = 1) or (Cells(1, 1).Value = 2) then
    3.         ActiveSheet.Pictures.Insert = "C:\" & cstr(Cells(1, 1).Value) & ".jpg"
    4.     End If
    5. End Sub

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  3. #3
    Banned debbie_82's Avatar
    Join Date
    Jan 2004
    Location
    inside a hollow void
    Posts
    104

    Neat...

    Your code is really neat... I could learn a lot from it...

  4. #4
    Supreme User Madboy's Avatar
    Join Date
    Oct 2003
    Location
    England
    Posts
    3,253
    Any idea on loading these through Image List?

  5. #5
    Registered User
    Join Date
    Feb 2004
    Posts
    52
    Code:
    Sub Dropdown1_Click()
        ActiveSheet.Pictures.Insert "C:\" & Dropdown1.ListIndex & ".jpg"
    End Sub
    It may not be Dropdown1.ListIndex. It may be .Index or one of the other properties that gives the Index of the selected item in the Combo Box. Check it out. Also, check to make sure that the Index starts at 1. If not start naming your pics "C:\0.jpg"

  6. #6
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    Originally posted by HardCode
    Code:
    Sub Dropdown1_Click()
        ActiveSheet.Pictures.Insert "C:\" & Dropdown1.ListIndex & ".jpg"
    End Sub
    It may not be Dropdown1.ListIndex. It may be .Index or one of the other properties that gives the Index of the selected item in the Combo Box. Check it out. Also, check to make sure that the Index starts at 1. If not start naming your pics "C:\0.jpg"
    the ItemData property of the combo box is perfect for this... ItemData holds an integer value which can be any type... so you dont have to rely on the index which has to be ordered... you can have duplicate ItemData values... etc... and you can assign a value to a newly added item in the combo by referencing

    Combo1.ListData(Combo1.NewIndex) = 10

    its real good for when you want text data in a combo to correspond to an ID number in a database...

Posting Permissions

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



Click Here to Expand Forum to Full Width