Solved

Can't Execute Code in Break Mode

Posted on 2014-02-13
22
504 Views
Last Modified: 2014-03-12
Hi there,

I know very little about macro language (fyi) but recorded one to do some conditional formatting.

I am trying to run the macro but received the message, "Can't execute code in break mode".

It runs the first formatting request and then stops.  It will do the same on other workbook pages but never moves to the next formatting request. It stops at the colour assigned to the second condition (see in bold please).

Thank you,
CS

Sub Colour_Coding()
'
' Colour_Coding Macro
' Colour Coding for Security Review Cases
'

'
    Columns("H:K").Select
    Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
        Formula1:="=""X"""
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    With Selection.FormatConditions(1).Font
        .Color = -16752384
        .TintAndShade = 0
    End With
    With Selection.FormatConditions(1).Interior
        .PatternColorIndex = xlAutomatic
        .Color = 13561798
        .TintAndShade = 0
    End With
    Selection.FormatConditions(1).StopIfTrue = False
    Cells.Select
    Selection.FormatConditions.Add Type:=xlTextString, String:="Has Access", _
        TextOperator:=xlContains
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    With Selection.FormatConditions(1).Font
       .Color = -16752384
        .TintAndShade = 0
    End With
    With Selection.FormatConditions(1).Interior
        .PatternColorIndex = xlAutomatic
        .Color = 13561798
        .TintAndShade = 0
    End With
    Selection.FormatConditions(1).StopIfTrue = False
    Selection.FormatConditions.Add Type:=xlTextString, String:="Yes", _
        TextOperator:=xlContains
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    With Selection.FormatConditions(1).Font
        .Color = -16752384
        .TintAndShade = 0
    End With
    With Selection.FormatConditions(1).Interior
        .PatternColorIndex = xlAutomatic
        .Color = 13561798
        .TintAndShade = 0
    End With
0
Comment
Question by:rporter45
  • 10
  • 6
  • 2
  • +2
22 Comments
 
LVL 26

Expert Comment

by:MacroShadow
Comment Utility
In the Visual Basic Editor click the "stop" button before running the code.
0
 

Author Comment

by:rporter45
Comment Utility
Hi there,

Thanks for the quick response - that gives me another error, Run-time error 1004
Application-defined or object-defined error.

Any ideas with this?

Thanks - CS
0
 
LVL 33

Expert Comment

by:Norie
Comment Utility
CS

What formatting do you want to apply and to which sheets/columns?
0
 

Author Comment

by:rporter45
Comment Utility
Here it goes!

If column H, I, J, K contains "X" then highlight cell  GREEN
If the words "has access" are present in the entire worksheet, then highlight cell GREEN
If the words "Yes" are present in the entire worksheet, then highlight cell GREEN

If the words "Cannot" are present in the entire worksheet, then highlight cell RED
If the words "No Access" are present in the entire worksheet, then highlight cell RED

If the words "Not Defined" are present in the entire worksheet, then highlight cell YELLOW

I recorded a macro yesterday when I went through each of these scenarios but it just doesn't want to work now,

Thanks - CS
0
 

Author Comment

by:rporter45
Comment Utility
Hi there,

Just checking in to see if there are any additional comments?

Thanks - CS
0
 
LVL 26

Accepted Solution

by:
MacroShadow earned 100 total points
Comment Utility
Try this:
Sub Colour_Coding()
'
' Colour_Coding Macro
' Colour Coding for Security Review Cases
'

    Dim rng As Range
    Set rng = Range("H:K")

    rng.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, Formula1:="=""X"""
    rng.FormatConditions(rng.FormatConditions.Count).SetFirstPriority
    With rng.FormatConditions(1).Font
        .Color = -16752384
        .TintAndShade = 0
    End With
    With rng.FormatConditions(1).Interior
        .PatternColorIndex = xlAutomatic
        .Color = 13561798
        .TintAndShade = 0
    End With
    rng.FormatConditions(1).StopIfTrue = False
    
    Set rng = ActiveSheet.Range
    
    rng.FormatConditions.Add Type:=xlTextString, String:="Has Access", TextOperator:=xlContains
    rng.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    With rng.FormatConditions(1).Font
        .Color = -16752384
        .TintAndShade = 0
    End With
    With rng.FormatConditions(1).Interior
        .PatternColorIndex = xlAutomatic
        .Color = 13561798
        .TintAndShade = 0
    End With
    rng.FormatConditions(1).StopIfTrue = False
    rng.FormatConditions.Add Type:=xlTextString, String:="Yes", TextOperator:=xlContains
    rng.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    With rng.FormatConditions(1).Font
        .Color = -16752384
        .TintAndShade = 0
    End With
    With rng.FormatConditions(1).Interior
        .PatternColorIndex = xlAutomatic
        .Color = 13561798
        .TintAndShade = 0
    End With
End Sub

Open in new window

0
 

Author Comment

by:rporter45
Comment Utility
MacroShadow;

Thanks very much!  I tried and am getting just one error;

Set rng = ActiveSheet.Range

Sorry - I'm pretty green with using Macros,

thank you!
CS
0
 

Author Comment

by:rporter45
Comment Utility
Sorry, I should have mentioned as well;

Run-time error 450:

Wrong number of arguments or invalid property assignment

Hope this helps - thanks!
Colleen
0
 
LVL 26

Expert Comment

by:MacroShadow
Comment Utility
1. Try Set rng = ActiveSheet.UsedRange
2. on which line does the error 450 occur?
0
 

Author Comment

by:rporter45
Comment Utility
That worked until the line Color = -16752384 - this now returns an error, Run-time error 1004 Application-defined or object-defined error.

See bold colour number below this is where the error occurs.

Thank you!

Sub Colour_Coding()
'
' Colour_Coding Macro
' Colour Coding for Security Review Cases
'

    Dim rng As Range
    Set rng = Range("H:K")

    rng.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, Formula1:="=""X"""
    rng.FormatConditions(rng.FormatConditions.Count).SetFirstPriority
    With rng.FormatConditions(1).Font
        .Color = -16752384
        .TintAndShade = 0
    End With
    With rng.FormatConditions(1).Interior
        .PatternColorIndex = xlAutomatic
        .Color = 13561798
        .TintAndShade = 0
    End With
    rng.FormatConditions(1).StopIfTrue = False
   
    Set rng = ActiveSheet.UsedRange
   
    rng.FormatConditions.Add Type:=xlTextString, String:="Has Access", TextOperator:=xlContains
    rng.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    With rng.FormatConditions(1).Font
        .Color = -16752384
        .TintAndShade = 0
    End With
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 26

Expert Comment

by:MacroShadow
Comment Utility
I can't reproduce the error.
0
 

Author Comment

by:rporter45
Comment Utility
I tried as well on another pc in the event that it is a windows 8 issue.   The same error occurred.  It's quite odd because it accepts the colour/number value above.

I am at a loss for this one and have researched on line but have not found any other answers.  I will wait for any other ideas prior to closing this,

Thanks - CS
0
 
LVL 26

Expert Comment

by:MacroShadow
Comment Utility
You can use the Request Attention feature to get additional assistance.
0
 

Author Comment

by:rporter45
Comment Utility
I guess I don't understand why it stops at the colour - it will even do this when I record only one macro at a time and run each because for some reason it compiles them.  I am on a windows 8 pc using office 2007 but it does the same on my vista machine using office 2007.

I'll see if this gets any response or will close shortly,

thanks very much,
CS
0
 
LVL 26

Expert Comment

by:MacroShadow
Comment Utility
Just a piece of advice, announcing that you are going to close the question soon is an almost sure way ward off any potential answers.
0
 

Author Comment

by:rporter45
Comment Utility
I think you misunderstood my comment - I was going to close if no additional help came through since I have researched extensively myself and have not found any answers anywhere else.  Perhaps the answer is not known?  I would not have closed without testing any suggestions that come through and giving each individual their due respect for assisting.

CS
0
 
LVL 19

Assisted Solution

by:regmigrant
regmigrant earned 100 total points
Comment Utility
Like macroshadow I can't reproduce the error.

What sort of screen/display are you using and what is the colour depth (16,24,32 bit?) is it adjustable on your system

Have you tried using a different number instead of that one?

You have listed several different error messages, can you confirm that you are getting 1004 at the .color line?
0
 
LVL 32

Assisted Solution

by:Robberbaron (robr)
Robberbaron (robr) earned 100 total points
Comment Utility
1/ why is color negative ?  not seen that before !  but appears it can be so.  What version of Excel are you running ?

try setting to any other color to test..  
.Color = RGB(0, 255, 0)

Open in new window


2/ in
With rng.FormatConditions(1).Font  , you are not necessarily working with the condition you just added because there may be more than one.  should be like the line above that works with Count property.
or better...
    Dim rng As Range
    Dim fmtcon1 As FormatCondition
    Set rng = ActiveSheet.UsedRange
    
    Set fmtcon1 = rng.FormatConditions.Add(Type:=xlCellValue, Operator:=xlEqual, Formula1:="=""X""")
    With fmtcon1
        .SetFirstPriority
        With .Font
            .Color = RGB(0, 255, 0)
            .TintAndShade = 0
        End With
        With .Interior
             .PatternColorIndex = xlAutomatic
            .Color = 13561798
            .TintAndShade = 0
        End With
        .StopIfTrue = False
    End With

Open in new window

0
 

Author Comment

by:rporter45
Comment Utility
Hi there,

Thank you for the responses - the negative is odd apparently and it is Office 2007 (I'm on windows 8 as well) but that is where it always stops, it will run through the first colour and then I receive the error message.

I will review and get back to you,

thank you again,
CS
0
 
LVL 32

Expert Comment

by:Robberbaron (robr)
Comment Utility
1/ from an msdn comment...
Because ToArgb returns an integer.  The highest byte of this integer is the alpha (transparency) channel.  In many cases, the alpha value will make the integers sign bit be negative.
so the negative is probably correct.

what result if you set color = 200 ?
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

PaperPort has a feature called the "Send To Bar". It provides a convenient, drag-and-drop interface for using other installed software, such as Microsoft Office. However, this article shows that the latest Office 2016 apps (installed with an Office …
Using Word 2013, I was experiencing some incredible lag when typing.  Here's what worked for me....
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

772 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

13 Experts available now in Live!

Get 1:1 Help Now