+ Reply to Thread
Results 1 to 6 of 6

Make a check box fill in a value?

  1. #1
    Bob
    Guest

    Make a check box fill in a value?

    Hi all,
    Is there a way in Excel to that when a user (on a protected document)
    checks or uncheks a Form Check Box to have that action fill in a value for a
    specific cell?

    Thanks for the help
    Bob



  2. #2
    Dave Peterson
    Guest

    Re: Make a check box fill in a value?

    I put a checkbox from the Forms toolbar on a worksheet.

    I pasted this into a General module:
    Option Explicit
    Sub testme()

    Dim myCell As Range
    Set myCell = ActiveSheet.Range("a1")

    If ActiveSheet.CheckBoxes(Application.Caller).Value = xlOn Then
    myCell.Value = "It's on"
    Else
    myCell.Value = "it's off"
    End If
    End Sub

    I rightclicked on that checkbox and assigned this macro to that that checkbox.

    I unlocked A1 of that worksheet (format|cell|protection tab)

    I protected the worksheet (tools|protection|protect sheet).

    And it worked fine.

    Bob wrote:
    >
    > Hi all,
    > Is there a way in Excel to that when a user (on a protected document)
    > checks or uncheks a Form Check Box to have that action fill in a value for a
    > specific cell?
    >
    > Thanks for the help
    > Bob


    --

    Dave Peterson

  3. #3
    Dave Peterson
    Guest

    Re: Make a check box fill in a value?

    In fact, if I kept A1 locked on that protected sheet, the macro could unprotect
    the worksheet (if it knows the password), do the work and then reprotect the
    password.

    Option Explicit
    Sub testme2()

    Dim myCell As Range
    Set myCell = ActiveSheet.Range("a1")

    ActiveSheet.Unprotect Password:="hi"

    If ActiveSheet.CheckBoxes(Application.Caller).Value = xlOn Then
    myCell.Value = "It's on"
    Else
    myCell.Value = "it's off"
    End If

    ActiveSheet.Protect Password:="hi"
    End Sub

    Bob wrote:
    >
    > Hi all,
    > Is there a way in Excel to that when a user (on a protected document)
    > checks or uncheks a Form Check Box to have that action fill in a value for a
    > specific cell?
    >
    > Thanks for the help
    > Bob


    --

    Dave Peterson

  4. #4
    Bob
    Guest

    Re: Make a check box fill in a value?

    That will work GREAT! Thanks for the help!

    -Bob


    "Dave Peterson" <[email protected]> wrote in message
    news:[email protected]...
    > In fact, if I kept A1 locked on that protected sheet, the macro could
    > unprotect
    > the worksheet (if it knows the password), do the work and then reprotect
    > the
    > password.
    >
    > Option Explicit
    > Sub testme2()
    >
    > Dim myCell As Range
    > Set myCell = ActiveSheet.Range("a1")
    >
    > ActiveSheet.Unprotect Password:="hi"
    >
    > If ActiveSheet.CheckBoxes(Application.Caller).Value = xlOn Then
    > myCell.Value = "It's on"
    > Else
    > myCell.Value = "it's off"
    > End If
    >
    > ActiveSheet.Protect Password:="hi"
    > End Sub
    >
    > Bob wrote:
    >>
    >> Hi all,
    >> Is there a way in Excel to that when a user (on a protected document)
    >> checks or uncheks a Form Check Box to have that action fill in a value
    >> for a
    >> specific cell?
    >>
    >> Thanks for the help
    >> Bob

    >
    > --
    >
    > Dave Peterson




  5. #5
    Bob
    Guest

    Re: Make a check box fill in a value?

    Dave,
    What about making this work using a Check Box from the "Control Toolbox"
    rather than the forms toolbox. Is that possible?


    "Bob" <[email protected]> wrote in message
    news:[email protected]...
    > That will work GREAT! Thanks for the help!
    >
    > -Bob
    >
    >
    > "Dave Peterson" <[email protected]> wrote in message
    > news:[email protected]...
    >> In fact, if I kept A1 locked on that protected sheet, the macro could
    >> unprotect
    >> the worksheet (if it knows the password), do the work and then reprotect
    >> the
    >> password.
    >>
    >> Option Explicit
    >> Sub testme2()
    >>
    >> Dim myCell As Range
    >> Set myCell = ActiveSheet.Range("a1")
    >>
    >> ActiveSheet.Unprotect Password:="hi"
    >>
    >> If ActiveSheet.CheckBoxes(Application.Caller).Value = xlOn Then
    >> myCell.Value = "It's on"
    >> Else
    >> myCell.Value = "it's off"
    >> End If
    >>
    >> ActiveSheet.Protect Password:="hi"
    >> End Sub
    >>
    >> Bob wrote:
    >>>
    >>> Hi all,
    >>> Is there a way in Excel to that when a user (on a protected
    >>> document)
    >>> checks or uncheks a Form Check Box to have that action fill in a value
    >>> for a
    >>> specific cell?
    >>>
    >>> Thanks for the help
    >>> Bob

    >>
    >> --
    >>
    >> Dave Peterson

    >
    >




  6. #6
    Dave Peterson
    Guest

    Re: Make a check box fill in a value?

    If you use the checkbox from the control toolbox, then click on the design mode
    icon (also on that toolbar) and double click on that checkbox.

    You'll be taken to where you should place the code.

    This worked for me:

    Option Explicit
    Private Sub CheckBox1_Click()

    Dim myCell As Range
    Set myCell = Me.Range("a1")

    Me.Unprotect Password:="hi"

    If Me.CheckBox1.Value = True Then
    myCell.Value = "It's on"
    Else
    myCell.Value = "it's off"
    End If

    Me.Protect Password:="hi"
    End Sub


    It's almost the same--notice that activesheet. was replaced with Me. Me is the
    object that owns the code--in this case it's the worksheet that holds that
    checkbox from the control toolbox toolbar.

    One nice thing about using the checkbox from the forms toolbar is you can assign
    the same macro to each checkbox. (You'd have to add a bit to make sure you got
    the correct corresponding cell, though.)

    But with the checkboxes from the control toolbox toolbar, each checkbox has its
    own code.

    Bob wrote:
    >
    > Dave,
    > What about making this work using a Check Box from the "Control Toolbox"
    > rather than the forms toolbox. Is that possible?
    >
    > "Bob" <[email protected]> wrote in message
    > news:[email protected]...
    > > That will work GREAT! Thanks for the help!
    > >
    > > -Bob
    > >
    > >
    > > "Dave Peterson" <[email protected]> wrote in message
    > > news:[email protected]...
    > >> In fact, if I kept A1 locked on that protected sheet, the macro could
    > >> unprotect
    > >> the worksheet (if it knows the password), do the work and then reprotect
    > >> the
    > >> password.
    > >>
    > >> Option Explicit
    > >> Sub testme2()
    > >>
    > >> Dim myCell As Range
    > >> Set myCell = ActiveSheet.Range("a1")
    > >>
    > >> ActiveSheet.Unprotect Password:="hi"
    > >>
    > >> If ActiveSheet.CheckBoxes(Application.Caller).Value = xlOn Then
    > >> myCell.Value = "It's on"
    > >> Else
    > >> myCell.Value = "it's off"
    > >> End If
    > >>
    > >> ActiveSheet.Protect Password:="hi"
    > >> End Sub
    > >>
    > >> Bob wrote:
    > >>>
    > >>> Hi all,
    > >>> Is there a way in Excel to that when a user (on a protected
    > >>> document)
    > >>> checks or uncheks a Form Check Box to have that action fill in a value
    > >>> for a
    > >>> specific cell?
    > >>>
    > >>> Thanks for the help
    > >>> Bob
    > >>
    > >> --
    > >>
    > >> Dave Peterson

    > >
    > >


    --

    Dave Peterson

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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