Solved

I receive a Runtime 13 error with conditional formatting code form an expert

Posted on 2008-06-25
12
197 Views
Last Modified: 2011-04-14
I received this code by doing a question search on EE for conditional formatting.
http://search.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Excel/Q_21455262.html?sfQueryTermInfo=1+4+condit+format+more+than
It works well in my test workbook, however when I applied it to my working workbook I received the
runtime error 13  Type Mismatch
The debugger stoped at:
Case ""
    Target.Interior.ColorIndex = xlNone
    Target.Font.ColorIndex = xlAutomatic

I am coping information in to my working model and there are no empty fields in my range.
Thanks
j
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, [A15:B800]) Is Nothing Then Exit Sub     'Formatting only applies to cells A15:B800
Select Case Target.Value
Case ""
    Target.Interior.ColorIndex = xlNone
    Target.Font.ColorIndex = xlAutomatic
Case "GP"
     Target.Font.ColorIndex = 5    'Black text
     Target.Font.Bold = True
Case "SPX"
     Target.Font.ColorIndex = 1    'Black text
     Target.Font.Bold = True
Case "HP"
     Target.Font.ColorIndex = 53    'Black text
     Target.Font.Bold = True
Case "SP"
     Target.Font.ColorIndex = 33    'Black text
     Target.Font.Bold = True
Case "AE"
     Target.Font.ColorIndex = 3    'Black text
     Target.Font.Bold = True
Case "WP"
     Target.Font.ColorIndex = 10    'Black text
     Target.Font.Bold = True
Case "EP"
     Target.Font.ColorIndex = 46    'Black text
     Target.Font.Bold = True
Case "MP"
     Target.Font.ColorIndex = 14    'Black text
     Target.Font.Bold = True
Case "RP"
     Target.Font.ColorIndex = 54    'Black text
     Target.Font.Bold = True
Case "JP"
     Target.Font.ColorIndex = 44    'Black text
     Target.Font.Bold = True
Case "JQ"
     Target.Font.ColorIndex = 45    'Black text
     Target.Font.Bold = True
 
 
 
End Select
End Sub

Open in new window

0
Comment
Question by:jgerardy
[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
  • 6
  • 5
12 Comments
 
LVL 6

Expert Comment

by:kosmoraios
ID: 21867824
Install Office Service Pack 3. See: http://support.microsoft.com/kb/821292

Hope that helps!
0
 
LVL 81

Expert Comment

by:zorvek (Kevin Jones)
ID: 21867982
Try this version:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim Cell As Range
If Intersect(Target, [A15:B800]) Is Nothing Then Exit Sub     'Formatting only applies to cells A15:B800
For Each Cell In Intersect(Target, [A15:B800])
Select Case Cell.Value
Case ""
    Cell.Interior.ColorIndex = xlNone
    Cell.Font.ColorIndex = xlAutomatic
Case "GP"
     Cell.Font.ColorIndex = 5    'Black text
     Cell.Font.Bold = True
Case "SPX"
     Cell.Font.ColorIndex = 1    'Black text
     Cell.Font.Bold = True
Case "HP"
     Cell.Font.ColorIndex = 53    'Black text
     Cell.Font.Bold = True
Case "SP"
     Cell.Font.ColorIndex = 33    'Black text
     Cell.Font.Bold = True
Case "AE"
     Cell.Font.ColorIndex = 3    'Black text
     Cell.Font.Bold = True
Case "WP"
     Cell.Font.ColorIndex = 10    'Black text
     Cell.Font.Bold = True
Case "EP"
     Cell.Font.ColorIndex = 46    'Black text
     Cell.Font.Bold = True
Case "MP"
     Cell.Font.ColorIndex = 14    'Black text
     Cell.Font.Bold = True
Case "RP"
     Cell.Font.ColorIndex = 54    'Black text
     Cell.Font.Bold = True
Case "JP"
     Cell.Font.ColorIndex = 44    'Black text
     Cell.Font.Bold = True
Case "JQ"
     Cell.Font.ColorIndex = 45    'Black text
     Cell.Font.Bold = True
 
 
 
End Select
Next Cell
End Sub

Kevin
0
 

Author Comment

by:jgerardy
ID: 21868199
I am not running XP.
I will try the version sent by Kevin

J
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:jgerardy
ID: 21868669
Kevin,
That worked well.  Can I change the Case "GP" to include a wildcard?  I have tried * ? and thy havent worked.

j
0
 
LVL 81

Expert Comment

by:zorvek (Kevin Jones)
ID: 21868758
No. But you can specify multiple strings:

Case "GP", "GX", "GA"

Kevin
0
 

Author Comment

by:jgerardy
ID: 21868779
Can I force the formating to the next cell B14?
0
 
LVL 81

Expert Comment

by:zorvek (Kevin Jones)
ID: 21868801
Yes.

   Cell.EntireRow.Columns("B").Interior.ColorIndex =

Kevin
0
 

Author Comment

by:jgerardy
ID: 21868848
Sorry Kevin,
Is this a relacement or an addition to the code.  Can you show me where?

j
0
 
LVL 81

Expert Comment

by:zorvek (Kevin Jones)
ID: 21868879
An addition.

Case "GP"
     Cell.Font.ColorIndex = 5    'Black text
     Cell.EntireRow.Columns("B").ColorIndex = 5
     Cell.Font.Bold = True

Kevin
0
 

Author Comment

by:jgerardy
ID: 21868909
I ran the new code and received a Run Time Error '438'
Object doesn't support the property or method.

at that line

j
0
 
LVL 81

Accepted Solution

by:
zorvek (Kevin Jones) earned 500 total points
ID: 21868934
Sorry about that:

Case "GP"
     Cell.Font.ColorIndex = 5    'Black text
     Cell.EntireRow.Columns("B").Cells.ColorIndex = 5
     Cell.Font.Bold = True

Kevin
0
 

Author Comment

by:jgerardy
ID: 21868958
You are the expert, but..
It worked when I added .Font after .Cells
Cell.EntireRow.Columns("B").Cells.Font.ColorIndex = 5

Thanks for the help.
j
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Cannot locate cell 15 42
Excel VBA Script 9 57
Excel - Active X Checkboxes Groups 45 36
Pull first name out of cell 2 28
Microsoft Office Picture Manager was included in Office 2003, 2007, and 2010, but not in Office 2013. Users had hopes that it would be in Office 2016/Office 365, but it is not. Fortunately, the same zero-cost technique that works to install it with …
How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

738 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