+ Reply to Thread
Results 1 to 11 of 11

Program a tick box with a macro

Hybrid View

  1. #1
    Registered User
    Join Date
    09-21-2014
    Location
    Wokingham
    MS-Off Ver
    Office 365
    Posts
    19

    Program a tick box with a macro

    Hi. When the tick box is checked I would like ' fill in cell a2' displayed as a message. and when the tick box is unchecked I would like ' remove data from cell a2' displayed in a message. Please could anyone help me? as I have no clue with macros. Thank you so much

  2. #2
    Forum Contributor vamosj's Avatar
    Join Date
    04-23-2004
    Location
    Oregon
    MS-Off Ver
    2010
    Posts
    294

    Re: Program a tick box with a macro

    Add the tick box, right click, assign macro, give it a name, then add this in the macro.

    Make sure you note the name of the tick box you use.

    Checkbox1 for example.

    if Checkbox1.value = true then msgbox("Fill in cell A2") else msgbox("Remove data from cell A2")



    Just doing that off the top of my head, but the code should look very similar to this.
    Last edited by vamosj; 04-15-2015 at 06:04 PM.
    Janos S. Vamos
    Data Systems Technician/Fire Controlman PO1(SW/AW)
    US Navy Retired


    Remember, Record Macro can be your friend for figuring out solutions.

    Good or Bad, let me know how I did by clicking on the "Add Reputation" * just to the lower left of here. it only takes a few seconds to let someone know.

  3. #3
    Registered User
    Join Date
    09-21-2014
    Location
    Wokingham
    MS-Off Ver
    Office 365
    Posts
    19

    Re: Program a tick box with a macro

    Thanks for the quick reply. I have tried this code and I get an error message saying compile error: Else without If?

  4. #4
    Forum Contributor
    Join Date
    10-03-2012
    Location
    USA
    MS-Off Ver
    2010
    Posts
    496

    Re: Program a tick box with a macro

    I am new in VBA also. Try this.


    Sub CB1()
        If ActiveSheet.Shapes("Check Box 1").ControlFormat.Value = 1 Then
        MsgBox "fill in cell a2"
        Else: MsgBox "remove data from cell a2"
        End If
    End Sub
    Last edited by Rocky2013; 04-15-2015 at 10:51 PM.

  5. #5
    Registered User
    Join Date
    09-21-2014
    Location
    Wokingham
    MS-Off Ver
    Office 365
    Posts
    19

    Re: Program a tick box with a macro

    I really don't understand... Sorry for sounding dum. All I want is a message box to appear when the checkbox is ticked stating one message and appearing when unchecked stating a 2nd message. Thx

  6. #6
    Forum Contributor vamosj's Avatar
    Join Date
    04-23-2004
    Location
    Oregon
    MS-Off Ver
    2010
    Posts
    294

    Re: Program a tick box with a macro

    Create a checkbox to use as your tick box. (Found in the developer tab)

    Right click on the checkbox and in the upper left corner of the spreadsheet you should be able to see the name of it.

    On the menu that popped up on the right click, select "Assign Macro"

    You can rename the macro if you want but if this is the only one there, just leave it as is and then select "New"

    In the visual basic window that pops up past the following code. Make sure to change the name (highlited in red) in line 1 of the code to the name of the checkbox.

    The message box should now pop up whenever the status of the checkbox is changed.


    Set ChkBx = ActiveSheet.Shapes("Check Box 1")  'Set this to whatever the name of the checkbox is
    If ChkBx.OLEFormat.Object.Value = 1 Then MsgBox ("Fill in cell A2") Else MsgBox ("Remove data from cell A2")
    Last edited by vamosj; 04-16-2015 at 12:37 PM. Reason: added info

  7. #7
    Registered User
    Join Date
    09-21-2014
    Location
    Wokingham
    MS-Off Ver
    Office 365
    Posts
    19

    Re: Program a tick box with a macro

    image.jpg this is what happens when I use the code your provided.. :/

  8. #8
    Forum Contributor
    Join Date
    10-03-2012
    Location
    USA
    MS-Off Ver
    2010
    Posts
    496

    Re: Program a tick box with a macro

    Does my code works for you?
    Last edited by Rocky2013; 04-16-2015 at 09:59 PM.

  9. #9
    Registered User
    Join Date
    09-21-2014
    Location
    Wokingham
    MS-Off Ver
    Office 365
    Posts
    19

    Re: Program a tick box with a macro

    Hi Rocky. No. I still get the Compile error message that says Else without if.

  10. #10
    Forum Contributor
    Join Date
    10-03-2012
    Location
    USA
    MS-Off Ver
    2010
    Posts
    496

    Re: Program a tick box with a macro

    I opened attached excel file from post#4, run and no issue to check and uncheck to prompt the messages.

    This file was created using Excel 2010.

    Below are the snap shots when I checked and unchecked the checkbox.
    Attached Images Attached Images
    Last edited by Rocky2013; 04-17-2015 at 06:23 AM.

  11. #11
    Forum Contributor vamosj's Avatar
    Join Date
    04-23-2004
    Location
    Oregon
    MS-Off Ver
    2010
    Posts
    294

    Re: Program a tick box with a macro

    Put the ELSE back up in the same line and remove the colon after it.


    If ChkBx.OLEFormat.Object.Value = 1 Then MsgBox ("Fill in cell A2") Else MsgBox ("Remove data from cell A2")

    Or you can do it this way.

    Set ChkBx = ActiveSheet.Shapes("Check Box 1")  'Set this to whatever the name of the checkbox is
    If ChkBx.OLEFormat.Object.Value = 1 Then 
         MsgBox ("Fill in cell A2") 
    Else 
         MsgBox ("Remove data from cell A2")
    End If

+ 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. [SOLVED] tick all check box in just one click and then count up the selected tick box...
    By pejoi in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 11-05-2013, 09:13 PM
  2. Need someone to program / help program a VBA / Excel Macro
    By JoeMcDome in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-04-2013, 04:03 PM
  3. Make 1 a tick in a tickbox and 0 no tick
    By ExcelFailure in forum Excel General
    Replies: 2
    Last Post: 04-02-2013, 07:28 AM
  4. Excel 2007 : one tick box selects multiple tick boxes
    By brentroberts in forum Excel General
    Replies: 2
    Last Post: 12-31-2011, 09:29 PM
  5. Tick Box Macro
    By Vlad999 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-18-2006, 01:26 AM

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