+ Reply to Thread
Results 1 to 4 of 4

how to make Combobox work for merged cells having data validation to increase font size.

  1. #1
    Registered User
    Join Date
    08-06-2014
    Location
    Pune, India
    MS-Off Ver
    2010
    Posts
    84

    how to make Combobox work for merged cells having data validation to increase font size.

    Hi All,
    I have found below code online, which checks if cell has data validation. It it has, it will make combo box visible and font size in drop down will increase. But this code does not work for merged cells.
    Please suggest correction to be made. There is also another code which works fine, but is based on double click event. I want to be it on selection event, so that if cells have validation, it will instantly show combo box. I am providing both the codes.

    Code 1: does not work for Merged cells.
    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("TempCombo")
    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 + 15
    .Height = Target.Height + 5
    .ListFillRange = ws.Range(str).Address
    .LinkedCell = Target.Address
    End With
    cboTemp.Activate
    'open the drop down list automatically
    Me.TempCombo.DropDown
    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
    '***NOTE: if KeyDown causes problems, change to KeyUp
    'Table with numbers for other keys such as Right Arrow (39)
    'https://msdn.microsoft.com/en-us/library/aa243025%28v=vs.60%29.aspx

    Private Sub TempCombo_KeyDown(ByVal _
    KeyCode As MSForms.ReturnInteger, _
    ByVal Shift As Integer)
    Select Case KeyCode
    Case 9 'Tab
    ActiveCell.Offset(0, 1).Activate
    Case 13 'Enter
    ActiveCell.Offset(1, 0).Activate
    Case Else
    'do nothing
    End Select
    End Sub

    2. Code works for both Merge and UN merge cells.

    '==========================
    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, _
    Cancel As Boolean)
    Dim str As String
    Dim cboTemp As OLEObject
    Dim ws As Worksheet
    Dim Tgt As Range
    Set Tgt = Target.Cells(1, 1)
    Set ws = ActiveSheet
    On Error GoTo errHandler

    If Tgt.Validation.Type = 3 Then
    Cancel = True
    End If

    Set cboTemp = ws.OLEObjects("TempCombo")
    On Error Resume Next
    With cboTemp
    .ListFillRange = ""
    .LinkedCell = ""
    .Visible = False
    End With
    On Error GoTo errHandler

    If Tgt.Validation.Type = 3 Then
    Application.EnableEvents = False
    str = Tgt.Validation.Formula1
    str = Right(str, Len(str) - 1)
    With cboTemp
    .Visible = True
    .Left = Tgt.Left
    .Top = Tgt.Top
    .Width = Target.Width + 15
    .Height = Target.Height + 5
    .ListFillRange = ws.Range(str).Address
    .LinkedCell = Tgt.Address
    End With
    cboTemp.Activate
    'open the drop down list automatically
    Me.TempCombo.DropDown
    End If

    errHandler:
    Application.EnableEvents = True
    Exit Sub

    End Sub
    '=========================================
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Dim str As String
    Dim cboTemp As OLEObject
    Dim ws As Worksheet
    Set ws = ActiveSheet

    Set cboTemp = ws.OLEObjects("TempCombo")
    On Error Resume Next
    If cboTemp.Visible = True Then
    With cboTemp
    .Top = 10
    .Left = 10
    .ListFillRange = ""
    .LinkedCell = ""
    .Visible = False
    .Value = ""
    End With
    End If

    errHandler:
    Application.EnableEvents = True
    Exit Sub

    End Sub

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: how to make Combobox work for merged cells having data validation to increase font siz

    Hi Isharwind,

    Try commenting out this line:

    Please Login or Register  to view this content.
    You do that by just putting an apostrophe in front of it

    BTW -
    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Registered User
    Join Date
    08-06-2014
    Location
    Pune, India
    MS-Off Ver
    2010
    Posts
    84

    Re: how to make Combobox work for merged cells having data validation to increase font siz

    Hi xladept,
    Thanks, that works.

  4. #4
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: how to make Combobox work for merged cells having data validation to increase font siz

    You're welcome and thanks for the rep!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. increase font size of list from data validatoin
    By superchew in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-16-2015, 02:04 PM
  2. Replies: 0
    Last Post: 11-25-2014, 07:08 AM
  3. Replies: 5
    Last Post: 04-22-2011, 10:21 AM
  4. increase size of text in data validation cell
    By jcavigli in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-28-2008, 01:22 PM
  5. How do I increase the font size in a cell validation list?
    By Brad Phelps in forum Excel General
    Replies: 2
    Last Post: 08-09-2006, 08:04 PM
  6. Script to increase font size of cells
    By Alan in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-06-2005, 12:10 AM
  7. Make Autofit row height work with merged cells
    By Franketh in forum Excel General
    Replies: 2
    Last Post: 04-06-2005, 06:06 PM

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.6.0 RC 1