+ Reply to Thread
Results 1 to 13 of 13
  1. #1
    Forum Contributor
    Join Date
    09-09-2009
    Location
    United States
    MS-Off Ver
    Excel 2003
    Posts
    155

    Multiple Combo Boxes

    Hi,

    Okay, I did away with the merged cells, and now I have a combo box in every cell that I want it in.

    My problem is, I would like to format each combo box seperately. Every cell that has a combo box in it has data vakidation activated. I copy and pasted code to get it to work. It works great, but I would still like to change the combo box size and tab and enter functions for each individual one. I created more than one combo box but I kept getting an error on them. Any help or knowledge would be greatly appreciated.

    I am posting just the code that I copy and pasted.

    Code:
    '=========================================
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Dim str As String
    Dim cboTemp As OLEObject
    Dim ws As Worksheet
    Set ws = ActiveSheet
    On Error GoTo errHandler
    
    If Target.Count > 1 Then GoTo exitHandler
    
    Set cboTemp = ws.OLEObjects("Locations")
      On Error Resume Next
    If cboTemp.Visible = True Then
      With cboTemp
        .Top = 10
        .Left = 10
        .ListFillRange = ""
        .LinkedCell = ""
        .Visible = False
        .Value = ""
      End With
    End If
    
      On Error GoTo errHandler
      If Target.Validation.Type = 3 Then
        'if the cell contains a data validation list
        Application.EnableEvents = False
        'get the data validation formula
        str = Target.Validation.Formula1
        str = Right(str, Len(str) - 1)
        With cboTemp
          'show the combobox with the list
          .Visible = True
          .Left = Target.Left
          .Top = Target.Top
          .Width = Target.Width + 195
          .Height = Target.Height + 4
          .ListFillRange = ws.Range(str).Address
          .LinkedCell = Target.Address
        End With
        cboTemp.Activate
      End If
    
    exitHandler:
      Application.ScreenUpdating = True
      Application.EnableEvents = True
      Exit Sub
    errHandler:
      Resume exitHandler
    
    End Sub
    '====================================
    'Optional code to move to next cell if Tab or Enter are pressed
    'from code by Ted Lanham
    Private Sub Locations_KeyDown(ByVal _
            KeyCode As MSForms.ReturnInteger, _
            ByVal Shift As Integer)
        Select Case KeyCode
            Case 9 'Tab
                ActiveCell.Offset(0, 4).Activate
            Case 13 'Enter
                ActiveCell.Offset(1, -1).Activate
            Case Else
                'do nothing
        End Select
    End Sub
    '====================================
    Thank you in advance.
    Last edited by whatsmyname; 09-21-2009 at 11:02 PM.

  2. #2
    Forum Moderator teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    2003 & 2010
    Posts
    10,042

    Re: Combo Box With Merged Cells?

    Hi,
    can't help you with the combo boxes, but merged cells are BAD BAD BAD and should be avoided because they lead to all kinds of problems. Instead use the formatting option to "Center across selection" in the Horizontal options of the Alignment tab.
    teylyn
    Microsoft MVP - Excel
    At Excelforum, you can say "Thank you!" by clicking the icon below the post.

    Avoid pie charts with more than two data points. Why? See here (pdf, 559 kb). The only acceptable pie chart is here.

  3. #3
    Forum Contributor
    Join Date
    09-09-2009
    Location
    United States
    MS-Off Ver
    Excel 2003
    Posts
    155

    Re: Combo Box With Merged Cells?

    Thank you,

    But, could you explain a little further by what you mean about formatting, please?

  4. #4
    Forum Moderator teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    2003 & 2010
    Posts
    10,042

    Re: Combo Box With Merged Cells?

    OK. More often than not merged cells are used to achieve the "look" of a cell spreading across several columns. Say you want A1, B1 and C1 to look as if it's one cell with some text in it. One way is to merge the three cells. But that can lead to all sorts of trouble, for example when you later change the layout of the workbook and want to add a new column between A and B, you first have to unmerge the cells.

    As an alternative to merging, select cells A1, B1 and C1, click Format - Cells, select the Alignment tab and in the dropdown box for Horizontal choose the option "Center across selection" Now your text in cell A1 is centered across the three columns. You can put a nice border around A1:C1 and they look like one cell. But they still are separate and you can insert columns without having to undo anything first.

    HTH
    teylyn
    Microsoft MVP - Excel
    At Excelforum, you can say "Thank you!" by clicking the icon below the post.

    Avoid pie charts with more than two data points. Why? See here (pdf, 559 kb). The only acceptable pie chart is here.

  5. #5
    Forum Contributor
    Join Date
    09-09-2009
    Location
    United States
    MS-Off Ver
    Excel 2003
    Posts
    155

    Re: Multiple Combo Boxes

    Okay,

    I got the formatting of cells figured out. and now I have my combo box working. The problem now is that I have a combo box in every data validation cell that I have. I want that but I also want to be able too size and set the different settings to each individual combo box for each data validation cell that I have.

    Any help would be greatly appreciated!!

    Thank you all!

  6. #6
    Forum Moderator pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2010
    Posts
    5,141

    Re: Multiple Combo Boxes

    Hi Whatsmyname
    can you please edit and add code tags to script in your first post as it makes the code easier to read?
    Place ['code] then the script ['/code] at the end
    regards pike

    If the solution helped please donate
    here to the RSPCA

    Sites worth visiting;

    J&R Solutions - royUK

    AJP Excel Information - Andy Pope

    Spreadsheet Toolbox

    JBeaucaires Excel Files

    VBA for smarties - snb

  7. #7
    Forum Contributor
    Join Date
    09-09-2009
    Location
    United States
    MS-Off Ver
    Excel 2003
    Posts
    155

    Re: Multiple Combo Boxes

    Okay,

    Pike, I am sorry about that. I believe that I have done it the proper way. I hope that helps.

    Thank you for your help.

  8. #8
    Forum Moderator pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2010
    Posts
    5,141

    Re: Multiple Combo Boxes

    whatsmyname
    To
    change the combo box size and tab and enter functions for each individual one
    In vb editor switch the "Design Mode"
    then in the work sheet Right click on Combobox and select View Properties.
    This is where custom setting are made. Or is there a pattern to the changes?
    Last edited by pike; 09-22-2009 at 06:20 AM. Reason: spellin?
    regards pike

    If the solution helped please donate
    here to the RSPCA

    Sites worth visiting;

    J&R Solutions - royUK

    AJP Excel Information - Andy Pope

    Spreadsheet Toolbox

    JBeaucaires Excel Files

    VBA for smarties - snb

  9. #9
    Forum Contributor
    Join Date
    09-09-2009
    Location
    United States
    MS-Off Ver
    Excel 2003
    Posts
    155

    Re: Multiple Combo Boxes

    Well,

    The thing is, is that I have multiple data validation cells. I want a combo box on each of these cells. But, I also want to be able to enter a specific size and enter and tab action setting for each combo box individually. I copied the code off of a contextures website. So, when it comes to the code that I have written, it might not be the best code to use.

    Right now I only have 1 combo box. I can set the size and enter and tab actions with the code that I have in there now. But, when I go and add another combo box, I do not know how to add that specific code for that specific combo box.

    I'm sorry that I am not that educated on these things. I do have a very basic idea of how this all works but basically my knowledge on this stuff is pre-k.

    Thank you for your help now and in the future. I hope that I explained everything thoroughly enough that you can understand what I am trying to do.

    Thank you.

  10. #10
    Forum Moderator pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2010
    Posts
    5,141

    Re: Multiple Combo Boxes

    How have you named the combo boxes
    regards pike

    If the solution helped please donate
    here to the RSPCA

    Sites worth visiting;

    J&R Solutions - royUK

    AJP Excel Information - Andy Pope

    Spreadsheet Toolbox

    JBeaucaires Excel Files

    VBA for smarties - snb

  11. #11
    Forum Contributor
    Join Date
    09-09-2009
    Location
    United States
    MS-Off Ver
    Excel 2003
    Posts
    155

    Re: Multiple Combo Boxes

    Yes I did. I have only a max of 2 combo boxes though. I actually have about 5 that I need to do. The reason why I haven't done more than 2 is because I can not get the second combo box to work on it's own. So I didn't want to put of a "mess" on the worksheet. I think my problem is in the code that I put in VB editor. I have tried to make another combo box and copy the code that I already have in VB, and just change the name's that are in there. It still did not work though. Unless you think I'm doing something wrong?

  12. #12
    Forum Moderator pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2010
    Posts
    5,141

    Re: Multiple Combo Boxes

    do you have a sample workbook that you can attach?
    regards pike

    If the solution helped please donate
    here to the RSPCA

    Sites worth visiting;

    J&R Solutions - royUK

    AJP Excel Information - Andy Pope

    Spreadsheet Toolbox

    JBeaucaires Excel Files

    VBA for smarties - snb

  13. #13
    Forum Contributor
    Join Date
    09-09-2009
    Location
    United States
    MS-Off Ver
    Excel 2003
    Posts
    155

    Re: Multiple Combo Boxes

    The file is to big to post. The code that I am using is in the first post of this thread. If that helps out at all. Is there anything else that I can do?

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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.2.0