Solved

Checkbox fires off a Statement

Posted on 2016-11-16
7
27 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 49

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 49

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:Bright01
ID: 41890120
Regonzo,

I get an error;

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

strSheets = "Sheet2,Sheet3"
0
 
LVL 49

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…

914 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now