Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Checkbox fires off a Statement

Posted on 2016-11-16
7
34 Views
Last Modified: 2016-11-16
EE Pros,

I've attached a Workbook where WS1 has a "checkbox".  My macro for on/off is not working and needs a tweek.  What I'm trying to do is when the checkbox is "checked", it will auto populate specified Worksheets within my Workbook with the word "Confidential".  I can adjust the Macro to choose the appropriate cell to populate, but don't know how to write the Macro to get it started/done.

Much thanks in advance.

B.
Checkbox.xlsm
0
Comment
Question by:Bright01
  • 4
  • 3
7 Comments
 
LVL 50

Expert Comment

by:Rgonzo1971
ID: 41889681
Hi,

pls try

Option Explicit
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
'Provides check button
If Not Intersect(Target, [C4]) Is Nothing Then
'If Target.Column = 3 Then
    Application.ScreenUpdating = False
  
    With Target
        If .Value = "P" Then
            .Value = ""
        ElseIf .Value = "" Then
            .Font.Name = "Wingdings 2"
            .Value = "P"
        End If
   End With
   End If
    Cancel = True
    Application.ScreenUpdating = True
End Sub

Open in new window

Regards
0
 

Author Comment

by:Bright01
ID: 41889962
Regonzo,

Greetings!  Thanks for picking this up.  The first half of my "ask"?  You nailed it.  Thank you.

The second half is an addition to the Macro that allows text to be placed in a specified cell on the other Sheets  (Sheet needs to be named and cell where text is going).

So..... if the cell on Sheet 1 is "checked", the text is auto placed on the other sheets listed in the Macro + the specific cell on that sheet.  In this case, it will say "confidential" on the other sheets if the box is checked.

Thank you,


B.
0
 
LVL 50

Expert Comment

by:Rgonzo1971
ID: 41890104
then try
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
'Provides check button
strSheets = "Sheet2,Sheet3"
strCellAddress = "B5"
If Not Intersect(Target, [C4]) Is Nothing Then
    Application.ScreenUpdating = False
  
    With Target
        If .Value = "P" Then
            .Value = ""
            For Each strSheet In Split(strSheets, ",")
                Sheets(strSheet).Range(strCellAdress).Value = ""
            Next
        ElseIf .Value = "" Then
            .Font.Name = "Wingdings 2"
            .Value = "P"
            For Each strSheet In Split(strSheets, ",")
                Sheets(strSheet).Range(strCellAdress).Value = "Confidential"
            Next
        End If
    End With
End If
Cancel = True
Application.ScreenUpdating = True
End Sub

Open in new window

Edited code
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:Bright01
ID: 41890120
Regonzo,

I get an error;

strSheets is not defined........

strSheets = "Sheet2,Sheet3"
0
 
LVL 50

Accepted Solution

by:
Rgonzo1971 earned 500 total points
ID: 41890126
then try
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
'Provides check button
Dim strSheet As Variant, strSheets As String
Dim strCellAddress As String
strSheets = "Sheet2,Sheet3"
strCellAddress = "B5"
If Not Intersect(target, [C4]) Is Nothing Then
    Application.ScreenUpdating = False
  
    With target
        If .Value = "P" Then
            .Value = ""
            For Each strSheet In Split(strSheets, ",")
                Sheets(strSheet).Range(strCellAddress).Value = ""
            Next
        ElseIf .Value = "" Then
            .Font.Name = "Wingdings 2"
            .Value = "P"
            For Each strSheet In Split(strSheets, ",")
                Sheets(strSheet).Range(strCellAddress).Value = "Confidential"
            Next
        End If
    End With
End If
Cancel = True
Application.ScreenUpdating = True
End Sub

Open in new window

0
 

Author Comment

by:Bright01
ID: 41890240
Regonzo,

Almost.  I tested it and it almost works.  Here are two questions;

1.) If I want the "confidential" text to show up on Sheets 2 and 3, but want it to show up and disappear (depending on the status of the checkmark -- on/off) how do I distinguish between the cells?  Right now, it shows up at the same sell on each Sheet.

2.) If I want to simply say "all sheets" so as not to have to identify each individual sheet, what line of code would I use to substitute where it tells which sheets to place the text?

Thank you,

B.
0
 

Author Closing Comment

by:Bright01
ID: 41890595
Rgonzo, Great Job!!!  Thank you very much!  Appreciate your help.  I'm going to post another request for the two additional enhancements to the macro.  You did a great job.  No scope creep here ;-)

Be good and again, much thanks,

B.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question