Solved

Excel VBA ComboBoxes added not fitting properly into cells

Posted on 2012-03-17
3
267 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Drop Down List with Unique/Distinct Values (enhancing the Combo-Box with a few steps and a little code) David miller (dlmille) Intro Have you ever created a data validation list from a database field or spreadsheet column (e.g., Zip Codes or Co…
Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

932 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

14 Experts available now in Live!

Get 1:1 Help Now