Solved

VBA - Run-time error 94: Invalid use of Null with Font Color Reference

Posted on 2009-04-06
7
600 Views
Last Modified: 2013-11-25
I have a data set that I am cleaning and one fo the unique features of a row I would like to keep is a specific font color. However, when I refer to Font.ColorIndex in my if statement, I get the error state. Below is my code. Any help would be much appreciated.

Thanks.
Sub Clean_Part1()
Dim i As Integer
Dim key_text As String
Dim fontcolor As Long
 
With Application.ActiveSheet
 
   For i = .Cells(.Cells.Rows.Count, 1).End(xlUp).Row To 1 Step -1
      key_text = Cells(i, 1).Value
      fontcolor = Cells(i, 1).Font.ColorIndex
        If fontcolor <> 10 And InStr(key_text, "Bed") = 0 And InStr(key_text, "Property Type:") = 0 And InStr(key_text, "{") = 0 Then Rows(i).EntireRow.Delete
    Next i
End With
End Sub

Open in new window

0
Comment
Question by:dhansen_
  • 3
  • 2
7 Comments
 
LVL 53

Expert Comment

by:Dhaest
ID: 24084294
Take a look at the following article.
http://www.cpearson.com/excel/colors.aspx
0
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 24086276
I don't think I've ever seen that error before. What is the value of i when it occurs and what is the font colour on that line?
0
 

Author Comment

by:dhansen_
ID: 24097033
I am not seeing the connection to the cpearson.com link and my problem. I based my code on that web page to begin with.
0
ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

 
LVL 85

Expert Comment

by:Rory Archibald
ID: 24097108
There is no link as far as I can tell either.
Rory
0
 

Author Comment

by:dhansen_
ID: 24097153
Unable to execute code in break mode and thus cannot answer rorya's q.
0
 
LVL 85

Accepted Solution

by:
Rory Archibald earned 125 total points
ID: 24098910
Try running this version - it will tell you the values on error:
 

Sub Clean_Part1()
Dim i As Integer
Dim key_text As String
Dim fontcolor As Long
on error goto err_handle
With Application.ActiveSheet
 
   For i = .Cells(.Cells.Rows.Count, 1).End(xlUp).Row To 1 Step -1
      key_text = Cells(i, 1).Value
      fontcolor = Cells(i, 1).Font.ColorIndex
        If fontcolor <> 10 And InStr(key_text, "Bed") = 0 And InStr(key_text, "Property Type:") = 0 And InStr(key_text, "{") = 0 Then Rows(i).EntireRow.Delete
    Next i
End With
 
exit sub
 
err_handle:
 msgbox "Row " & i & " caused the error"
End Sub

Open in new window

0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VBA copy column paste as value 5 21
VBA: copy range dynamically based on config sheet v2 3 34
locking multiple column ranges 10 25
Error with a code discussed on this page 5 14
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…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

773 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