Solved

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

Posted on 2009-04-06
7
583 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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
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…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

758 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

21 Experts available now in Live!

Get 1:1 Help Now