?
Solved

Checkbox fires off a Statement

Posted on 2016-11-16
7
Medium Priority
?
45 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
[X]
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
  • 4
  • 3
7 Comments
 
LVL 52

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 52

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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Bright01
ID: 41890120
Regonzo,

I get an error;

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

strSheets = "Sheet2,Sheet3"
0
 
LVL 52

Accepted Solution

by:
Rgonzo1971 earned 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

777 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