Consulting

Results 1 to 4 of 4

Thread: Controls on sheet OTF

  1. #1
    VBAX Regular
    Joined
    Mar 2007
    Posts
    47
    Location

    Controls on sheet OTF

    Hello!

    Is it possible to make controls (check box) on every row in column X on the fly with some code added to it (options: yes, no, possible)?

    thanx

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    How can you have 3 options with a 2 state checkbox?

    Here is an alternate approach, it puts a tick mark in a cell when double-clicking it

    [vba]

    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    Const WS_RANGE As String = "H1:H10" '<== change to suit

    On Error GoTo err_handler
    Application.EnableEvents = False
    If Not Application.Intersect(Target, Range(WS_RANGE)) Is Nothing Then
    With Target
    .Font.Name = "Marlett"
    Select Case .Value
    Case "": .Value = "a"
    Case "a": .Value = ""
    End Select
    End With
    Cancel = True
    End If
    err_handler:
    Application.EnableEvents = True
    End Sub
    [/vba]

    This is worksheet event code, which means that it needs to be
    placed in the appropriate worksheet code module, not a standard
    code module. To do this, right-click on the sheet tab, select
    the View Code option from the menu, and paste the code in.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Regular
    Joined
    Mar 2007
    Posts
    47
    Location
    Quote Originally Posted by xld
    How can you have 3 options with a 2 state checkbox?

    Here is an alternate approach, it puts a tick mark in a cell when double-clicking it

    [vba]

    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    Const WS_RANGE As String = "H1:H10" '<== change to suit

    On Error GoTo err_handler
    Application.EnableEvents = False
    If Not Application.Intersect(Target, Range(WS_RANGE)) Is Nothing Then
    With Target
    .Font.Name = "Marlett"
    Select Case .Value
    Case "": .Value = "a"
    Case "a": .Value = ""
    End Select
    End With
    Cancel = True
    End If
    err_handler:
    Application.EnableEvents = True
    End Sub
    [/vba]
    This is worksheet event code, which means that it needs to be
    placed in the appropriate worksheet code module, not a standard
    code module. To do this, right-click on the sheet tab, select
    the View Code option from the menu, and paste the code in.
    ups! sorry! i didn't mean check box... I mean combo box... anyway thanx for code, i'll try it

  4. #4
    VBAX Master
    Joined
    Jun 2007
    Location
    East Sussex
    Posts
    1,110
    Location
    You can do that with Data Validation - just set 'Allow' option to 'List' and enter this as source:Yes, No, Possible
    Regards,
    Rory

    Microsoft MVP - Excel

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •