Closed Thread
Results 1 to 13 of 13

[SOLVED] making a checkbox appear and disappear based on a cell's value

  1. #1
    yoram
    Guest

    [SOLVED] making a checkbox appear and disappear based on a cell's value

    yoramsk@gmail.com
    Jan 23, 9:22 am show options

    From: "yora...@gmail.com" <yora...@gmail.com> - Find messages by this
    author
    Date: Mon, 23 Jan 2006 15:22:13 -0000
    Local: Mon, Jan 23 2006 9:22 am
    Subject: making a checkbox appear and disappear based on a cell's value

    Reply | Reply to Author | Forward | Print | Individual Message | Show
    original | Remove | Report Abuse

    i know this might have been addressed before but i cannot get the
    following code to work. basically i want a checkbox to appear if cell
    A1 is = "abc" and disappear if it is anything else. this checkbox was
    created from the controls toolbar. so i started off the checkbox set
    to invisible and then have an if/then statement to make it visible.
    what am i doing wrong? right now the checkbox will not reappear.
    thanks in advance for any help.


    Private Sub Worksheets_Calculate()
    ActiveSheet.CheckBox15.Visible = False
    If Worksheets("Sheet1").Range("A1").Value = "abc" Then
    ActiveSheet.CheckBox15.Visible = True
    Else
    ActiveSheet.CheckBox15.Visible = False
    End If
    End Sub


  2. #2
    Jim Thomlinson
    Guest

    RE: making a checkbox appear and disappear based on a cell's value

    You should reference the sheet directly, not as the active sheet.

    Private Sub Worksheets_Calculate()

    With Sheet1
    .CheckBox15.Visible = False
    If .Range("A1").Value = "abc" Then
    .CheckBox15.Visible = True
    Else
    .CheckBox15.Visible = False
    End If
    End With
    End Sub

    Let me know if that works or not... It worked for me...
    --
    HTH...

    Jim Thomlinson


    "yoram" wrote:

    > yoramsk@gmail.com
    > Jan 23, 9:22 am show options
    >
    > From: "yora...@gmail.com" <yora...@gmail.com> - Find messages by this
    > author
    > Date: Mon, 23 Jan 2006 15:22:13 -0000
    > Local: Mon, Jan 23 2006 9:22 am
    > Subject: making a checkbox appear and disappear based on a cell's value
    >
    > Reply | Reply to Author | Forward | Print | Individual Message | Show
    > original | Remove | Report Abuse
    >
    > i know this might have been addressed before but i cannot get the
    > following code to work. basically i want a checkbox to appear if cell
    > A1 is = "abc" and disappear if it is anything else. this checkbox was
    > created from the controls toolbar. so i started off the checkbox set
    > to invisible and then have an if/then statement to make it visible.
    > what am i doing wrong? right now the checkbox will not reappear.
    > thanks in advance for any help.
    >
    >
    > Private Sub Worksheets_Calculate()
    > ActiveSheet.CheckBox15.Visible = False
    > If Worksheets("Sheet1").Range("A1").Value = "abc" Then
    > ActiveSheet.CheckBox15.Visible = True
    > Else
    > ActiveSheet.CheckBox15.Visible = False
    > End If
    > End Sub
    >
    >


  3. #3
    Paul
    Guest

    RE: making a checkbox appear and disappear based on a cell's value

    maybe if you coerced the value from the cell into a string? or format the
    cell to text.

  4. #4
    yoram
    Guest

    Re: making a checkbox appear and disappear based on a cell's value

    Thanks for the prompt response. Unfortunately, the code still doesn't
    work for me. Changing the cell's value doesn't make the checkbox
    visibile/invisible. I am running 2002 and tried with protection on/off.


  5. #5
    Peter T
    Guest

    Re: making a checkbox appear and disappear based on a cell's value

    A typo in your original code continued into Jim's

    > Private Sub Worksheets_Calculate()


    Private Sub Worksheet_Calculate()


    When you say "Changing the cell's value" if the cell is not a formula
    changing it's value will not trigger a calculation event. So use the Change
    event

    Private Sub Worksheet_Change(ByVal Target As Range)

    If Not Intersect(Target, Range("a1")) Is Nothing Then
    CheckBox1.Visible = UCase(Range("A1") = "ABC")
    End If

    End Sub

    As the code is in a worksheet module everything defaults to the sheet, even
    if it's not the active sheet. For clarity could qualify with Me

    Regards,
    Peter T


    "yoram" <yoramsk@gmail.com> wrote in message
    news:1138048027.329955.318120@g14g2000cwa.googlegroups.com...
    > Thanks for the prompt response. Unfortunately, the code still doesn't
    > work for me. Changing the cell's value doesn't make the checkbox
    > visibile/invisible. I am running 2002 and tried with protection on/off.
    >




  6. #6
    Jim Thomlinson
    Guest

    Re: making a checkbox appear and disappear based on a cell's value

    Sorry about taking so long... The code that you posted needs to be in the
    ThisWorkbook module, and events must be enabled. If it is in thisworkbook
    then run this code to reset your events...

    Sub test
    Application.enableevents = true
    end sub

    You should also check for where it was set to false and ensure that that
    code is working properly.
    --
    HTH...

    Jim Thomlinson


    "yoram" wrote:

    > Thanks for the prompt response. Unfortunately, the code still doesn't
    > work for me. Changing the cell's value doesn't make the checkbox
    > visibile/invisible. I am running 2002 and tried with protection on/off.
    >
    >


  7. #7
    yoram
    Guest

    Re: making a checkbox appear and disappear based on a cell's value

    Awesome. Many thanks Peter and Jim.


  8. #8
    yoram
    Guest

    Re: making a checkbox appear and disappear based on a cell's value

    Awesome. Many thanks Peter and Jim.


  9. #9
    Jim Thomlinson
    Guest

    Re: making a checkbox appear and disappear based on a cell's value

    Sorry... Not in Thisworkbook, but rather in the sheet that is the target...
    Also Peter has a better eye than I do. There is a typo in the procedure
    name... Monday is getting the best of me here...
    --
    HTH...

    Jim Thomlinson


    "Jim Thomlinson" wrote:

    > Sorry about taking so long... The code that you posted needs to be in the
    > ThisWorkbook module, and events must be enabled. If it is in thisworkbook
    > then run this code to reset your events...
    >
    > Sub test
    > Application.enableevents = true
    > end sub
    >
    > You should also check for where it was set to false and ensure that that
    > code is working properly.
    > --
    > HTH...
    >
    > Jim Thomlinson
    >
    >
    > "yoram" wrote:
    >
    > > Thanks for the prompt response. Unfortunately, the code still doesn't
    > > work for me. Changing the cell's value doesn't make the checkbox
    > > visibile/invisible. I am running 2002 and tried with protection on/off.
    > >
    > >


  10. #10
    yoram
    Guest

    Re: making a checkbox appear and disappear based on a cell's value

    Awesome. Many thanks Peter and Jim.


  11. #11
    Peter T
    Guest

    Re: making a checkbox appear and disappear based on a cell's value

    Obviously one of those typo days -

    > CheckBox1.Visible = UCase(Range("A1") = "ABC")


    CheckBox1.Visible = UCase(Range("A1")) = "ABC"

    (assuming case sensitive condition is not required)

    Regards,
    Peter T

    "Peter T" <peter_t@discussions> wrote in message
    news:uVKuQNGIGHA.2040@TK2MSFTNGP14.phx.gbl...
    > A typo in your original code continued into Jim's
    >
    > > Private Sub Worksheets_Calculate()

    >
    > Private Sub Worksheet_Calculate()
    >
    >
    > When you say "Changing the cell's value" if the cell is not a formula
    > changing it's value will not trigger a calculation event. So use the

    Change
    > event
    >
    > Private Sub Worksheet_Change(ByVal Target As Range)
    >
    > If Not Intersect(Target, Range("a1")) Is Nothing Then
    > CheckBox1.Visible = UCase(Range("A1") = "ABC")
    > End If
    >
    > End Sub
    >
    > As the code is in a worksheet module everything defaults to the sheet,

    even
    > if it's not the active sheet. For clarity could qualify with Me
    >
    > Regards,
    > Peter T
    >
    >
    > "yoram" <yoramsk@gmail.com> wrote in message
    > news:1138048027.329955.318120@g14g2000cwa.googlegroups.com...
    > > Thanks for the prompt response. Unfortunately, the code still doesn't
    > > work for me. Changing the cell's value doesn't make the checkbox
    > > visibile/invisible. I am running 2002 and tried with protection on/off.
    > >

    >
    >




  12. #12
    Registered User
    Join Date
    05-12-2021
    Location
    México
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (16.0.13530.20054)
    Posts
    17

    Unhappy Re: [SOLVED] making a checkbox appear and disappear based on a cell's value

    Dear Community:

    I'm new at coding and I'm trying to do the same as the initial thread. But for some reason I'm getting this error

    Run-time error '424'
    Object required


    I'm attaching the workbook that I'm trying to use.
    By default, the cell G8 has a value of "Please select the Probability". After we click the command button "Calculate Probability", a form pops up, we need to provide answers to the questionnaire and click on the button "Calculate".
    With the button, a calculation begins and the results affects the content of cell G8 and it triggers the CheckBox to be enabled. The condition to enable the CheckBox is that the content of the G8 cell must be different from "Please select the Probability".

    Here is the code:

    Private Sub cmdCalcProb_Click()

    With Worksheets("Data")
    .Range("C1:C12").ClearContents
    End With

    With Worksheets("Probability+Impact")
    If .Range("G8").Value = "Please select the Probability" Then
    .CheckBox1.Enabled = False
    .CheckBox1.Value = False
    Else
    .CheckBox1.Enabled = True
    End If
    End With

    Probability.Show

    End Sub


    Highlighted is the line where I get the error.
    Hope someone could help me, please
    Attached Files Attached Files
    Last edited by Magmarinita; 05-12-2021 at 10:59 PM.

  13. #13
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2503 (Windows 11 Home 24H2 64-bit)
    Posts
    90,309

    Re: [SOLVED] making a checkbox appear and disappear based on a cell's value

    Administrative Note:

    Welcome to the forum.

    We are happy to help, however whilst you feel your request is similar to this thread, experience has shown that things soon get confusing when answers refer to particular cells/ranges/sheets which are unique to your post and not relevant to the original.

    Please see Forum Rule #4 about hijacking and start a new thread for your query.

    If you are not familiar with how to start a new thread see the FAQ: How to start a new thread
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

Closed 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