Solved

Need Help with a Macro to reverse an action

Posted on 2014-12-08
15
96 Views
Last Modified: 2014-12-13
EE Pros,

I have a very nice workbook/sheet that EE Pros helped me build that has three tabs.  It works great until I come to a situation where I need to "uncheck" a selection.

Scenario:  When you go to the "Use_Case" tab, you can click on the black box to the left and a check mark appears.  This selection is then placed on line G800 in the Validation DB tab.  A formula picks it up in the Use_Case_Priority Tab" so any selection ends up here.

Problem:  When I uncheck a box on the "Use Case" tab, it doesn't deselect it from the list that is created in the other two tabs.  That's my problem.  I want to be able to select Cases and have them show up or not show up (based on selected or deselected check marks).  The macro only allows for selection, not de-selection.  

Workbook attached for your review.  For someone with Macro skills, this should be a rather quick fix.

Thank you in advance,

Bright 01
Fix-Check-Marks-v3.xlsm
0
Comment
Question by:Bright01
  • 7
  • 7
15 Comments
 
LVL 27

Accepted Solution

by:
Glenn Ray earned 500 total points
ID: 40487962
I modified the sumup subroutine to clear the values in the ValidationDB sheet (G800:G812) before processing.  This ensures that there is always a "clean slate" before applying the checked categories on the Use_Cases sheet.  

See the attached, modified workbook and let me know if there are any issues.

Regards,
-Glenn

PS  I also took the liberty of making spelling corrections in the ValidationDB sheet. GR
EE-Fix-Check-Marks-v3.xlsm
0
 

Author Comment

by:Bright01
ID: 40488257
Glenn,

This is great!  It works perfectly in my production model....except for one item (and I apologize I left this out)......... I have three cells to the right of Use_Case_Priority WS that need to be reset / cleared if the box is unchecked on the PMQ_Use_Case.  

To see what I mean, I've included the addition.  You will see 3 cases with 3 cells to the right filled out.   When you deselect a case, your code works perfectly; but the three cells to the right do not clear.

I really appreciate the help.....and I'm sorry for the scope creep.

B.
Copy-of-EE-Fix-Check-Marks-v4.xlsm
0
 
LVL 27

Expert Comment

by:Glenn Ray
ID: 40489279
Well, I'd hoped it would be as simple as adding another small block of code in the sumup routine to clear out those cells:
    With Worksheets("Use_Case_Priority")
        '.Unprotect Password:="jam"
        .Range("C5:E14") = ""
        '.Protect Password:="jam"
    End With

Open in new window


However, after testing this I realized that this would clear all Factor inputs on the Use_Case_Priority worksheet, which may not be exactly what you'd like.  I imagine you'd want to preserve values for Use Cases that remain (not un-checked), right?

-Glenn
0
 

Author Comment

by:Bright01
ID: 40489568
Yes correct.   I can live without the change but to make it perfect, it needs to delete the three entries next to the "unchecked" selection and shift any other selection up so that it continues to be a list rather then a list with gaps.  Again, if this is complicated.... let's go with the great work you have already provided me.

B.
0
 
LVL 27

Expert Comment

by:Glenn Ray
ID: 40491761
I'll dig into this today and see if I can update the code to do just that.  I expected that was the hope-for behavior.
0
 
LVL 27

Expert Comment

by:Glenn Ray
ID: 40492000
As a side note, your example workbook contains nearly one thousand range names, most of which have no valid reference or value.  Here's a list of them (generated using the ASAP Utilities add-in for Excel).

You may want to consider removing those.  Additionally, there are over 3,400 styles in there.  I suspect these and the range names come from copied-and-pasted sheets from other workbooks over time.

-Glenn
EE-RangeNames-Fix-Check-Marks.xlsx
0
 

Author Comment

by:Bright01
ID: 40492530
You made me smile this morning (I'm in Asia today and it's early).  

You are correct on the Range names.   I've always had a problem mass deleting range names from copied files.  I'll try the ASAP utility and see if it offers a way to determine which Range names can, should be selectively deleted.  

Thank you!

Should I go ahead and close out the original "ask"?  Your work was perfect for what I had asked for.... I can author another question.

b.
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:Bright01
ID: 40492990
I've requested that this question be closed as follows:

Accepted answer: 0 points for Bright01's comment #a40488257

for the following reason:

Glenn,  Great work "thank you".   Your quick response was just what I needed and while this will continue to evolve... I really appreciate you stepping up to help me.  Long live EE.

B.
0
 
LVL 27

Expert Comment

by:Glenn Ray
ID: 40492988
Instead of closing, could you either select my earlier answer as a solution to your initial question or let me go ahead and try to resolve the issue with the additional fields/columns?

Also, I have a macro that does a pretty good job removing unneeded styles and another that removes bad range names and can provide them once I get home.

Regards,
Glenn
Sent from my Windows Phone
0
 
LVL 27

Expert Comment

by:Glenn Ray
ID: 40492991
asked for solution selection or additional time to resolve
0
 

Author Comment

by:Bright01
ID: 40493260
Absolutely!  Just wanted to be respectful of your support.

B
0
 
LVL 27

Expert Comment

by:Glenn Ray
ID: 40494188
Still finishing up code to retain the Factors, but here are a couple of subroutines that will help clean up the Ranges and Styles.

This will remove most styles; there may be some that will not remove (I noticed a few in Cyrillic that could not be deleted).
Sub DelStyle()
    Dim x As Long
    ' macro from Dave Peterson, Excel MVP
    On Error Resume Next
    Dim myStyle As Style
    For Each myStyle In ActiveWorkbook.Styles
        If myStyle.BuiltIn Then
            'do nothing
        Else
            myStyle.Delete
            x = x + 1
        End If
    Next myStyle
    MsgBox "Done! Styles removed: " & x, vbOKOnly, "Deleted Styles"
End Sub

Open in new window

A more-thorough tool that I highly recommend is the XLStylesTool from Sergei Gundorov.

This macro will remove range names with invalid references (#REF!).
Sub Remove_Bad_Names()
    'Removes range names with invalid references (non-existent)
    Dim testRng As Range
    Dim myName As Name
    Application.Calculation = xlCalculationManual
    For Each myName In ActiveWorkbook.Names
        Set testRng = Nothing
        On Error Resume Next
        Set testRng = myName.RefersToRange
        On Error GoTo 0
        If testRng Is Nothing Then
            'doesn't refer to a real range
            'MsgBox myName.Name
            myName.Delete
        End If
    Next myName
    Calculate
    Application.Calculation = xlCalculationAutomatic
End Sub

Open in new window


-Glenn
0
 

Author Comment

by:Bright01
ID: 40495180
Glenn,

The style sub ran perfectly.  It cleared over 3K of them.  What is a style in Excel?

and

I got a 1004 Error on the other Sub on line myName.Delete.  Any coaching on this?

B.
0
 

Author Closing Comment

by:Bright01
ID: 40497690
Glenn,

Great job on my original request!!!  This works in my production version.  I will issue another question about deleting the 3 fields at the end of the routine.

Appreciate both the help as well as the tips on cleaning up my Range names.

All the best,

B.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

A2 = A1 That kind of cell reference is relative.  If you copy it from A2 to B2, then B2 will get this: B2 = B1 That's all fine and good, but if you then insert a new row above row 2, you'll find: A3 = A1 B3 = B1 This is intentional. …
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…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
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…

759 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

23 Experts available now in Live!

Get 1:1 Help Now