Solved

Excel VBA ComboBoxes added not fitting properly into cells

Posted on 2012-03-17
3
266 Views
Last Modified: 2012-03-18
Hi. I am using the following code to ass a ComboBox to every cell in a selection.
I need the cells to fit properly but they aren't as shown in the picture. How do I get them to fit properly

Sub ControlToCell()
     
    Dim iLeft As Integer
    Dim iTop As Integer
    Dim iWidth As Integer
    Dim iHeight As Integer
    Dim cell As Range
     
    For Each cell In Selection
       
        cell.Select
        iLeft = ActiveCell.Left
        iTop = ActiveCell.Top
        iWidth = ActiveCell.Width
        iHeight = ActiveCell.Height
         
          ActiveSheet.OLEObjects.Add(ClassType:="Forms.ComboBox.1", Link:=False _
        , DisplayAsIcon:=False, Left:=iLeft, Top:=iTop, Width:=iWidth, Height:= _
        iHeight).Select
       
       
    Next cell
     
End Sub
image3.png
0
Comment
Question by:murbro
3 Comments
 
LVL 33

Accepted Solution

by:
Norie earned 250 total points
ID: 37733372
Try adding a pixel (I think they're pixels, might be points) or two to the width and height.
0
 
LVL 41

Assisted Solution

by:dlmille
dlmille earned 250 total points
ID: 37733380
This is what I use with my DynamicDV! utility:http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Excel/A_6429-Part-II-Drop-Down-List-with-Unique-Distinct-Values-ComboBox-ListBox-and-Data-Validation-List-Bonus.html

Dim cboTemp As OLEObject
Dim Target As Range

    Set Target = Range("A15")
   
    Set cboTemp = ActiveSheet.OLEObjects.Add(classtype:="Forms.ComboBox.1")
    cboTemp.Name = "TempCombo"
       
           
    With cboTemp

        .Visible = True
        .Left = Target.Left
        .Top = Target.Top
        .Width = Target.Width + 5
        .Height = Target.Height + 5

    End With
0
 

Author Closing Comment

by:murbro
ID: 37735067
Thanks very much
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Dealing with unintended Excel Active-X resizing quirks (VBA code simulates "self correction") David Miller (dlmille) Intro Not everyone is a fan of Active-X controls in spreadsheets (as opposed to the UserForm approach, the older Form controls …
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now