Solved

Can't Execute Code in Break Mode

Posted on 2014-02-13
22
548 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
[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
  • 10
  • 6
  • 2
  • +2
22 Comments
 
LVL 27

Expert Comment

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

Author Comment

by:rporter45
ID: 39856639
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 34

Expert Comment

by:Norie
ID: 39856659
CS

What formatting do you want to apply and to which sheets/columns?
0
Technology Partners: 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:rporter45
ID: 39856879
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
ID: 39867393
Hi there,

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

Thanks - CS
0
 
LVL 27

Accepted Solution

by:
MacroShadow earned 100 total points
ID: 39867514
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
ID: 39867581
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
ID: 39867591
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 27

Expert Comment

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

Author Comment

by:rporter45
ID: 39867996
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
 
LVL 27

Expert Comment

by:MacroShadow
ID: 39868215
I can't reproduce the error.
0
 

Author Comment

by:rporter45
ID: 39868318
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 27

Expert Comment

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

Author Comment

by:rporter45
ID: 39868952
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 27

Expert Comment

by:MacroShadow
ID: 39869039
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
ID: 39869192
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
ID: 39878409
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
ID: 39880209
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
ID: 39882469
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)
ID: 39885217
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

Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

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

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.
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

696 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