?
Solved

Excel VBA ComboBoxes added not fitting properly into cells

Posted on 2012-03-17
3
Medium Priority
?
274 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:Murray Brown
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 34

Accepted Solution

by:
Norie earned 1000 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 42

Assisted Solution

by:dlmille
dlmille earned 1000 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:Murray Brown
ID: 37735067
Thanks very much
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

770 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