Solved

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

Posted on 2009-04-06
7
589 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Search Workbook, then move rows to new sheet 13 31
MsgBox 4 43
ADD New Entries 7 15
Move entire row to another workbook based on cell value 20 39
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

932 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

10 Experts available now in Live!

Get 1:1 Help Now