VBA not cell filling correctly in IF/THEN structure

kmmsquared

New Member
Joined
Jan 7, 2011
Messages
33
Hello,

I am using the following code below to filter a column and color the rows of that contain cells with the correct values (this occurs 3x in my code). My problem is the if e is nothing then the column still colors. I only want the rows to be colored if e is not nothing. Any suggestions would be greatly appreciated-there is probably something simple that I can't think of. Thanks!

Code:
With Sheets("Sheet1")
   lngLastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
   s = Application.WorksheetFunction.Match("Esc", Range("1:1"), 0)
   e = Range("E2:E" & lngLastRow).SpecialCells(xlCellTypeVisible)      
 
Columns("E").AutoFilter Field:=1, Criteria1:="MAKE"
 
[COLOR=red]If Not e Is Nothing Then
Range(Cells(2, 1), Cells(lngLastRow, s)).SpecialCells(xlCellTypeVisible).Activate
With Selection.Interior
.ThemeColor = xlThemeColorAccent5
.TintAndShade = 0.599993896298105
End With
[/COLOR]End If
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
I only posted a portion of my code--I have an end with at the end of the sub after the code cycles through the other 2 filters.
 
Upvote 0
Isn't the "IS NOTHING" designed to only speak to OBJECT VARIABLES?
AND.. OBJECT VARIABLES are ONLY set by using the Key Word "SET"
So... Wouldn't you need to say "Set e = ???"

Currently e is a normal variable, not as Object Variable.
 
Upvote 0

Forum statistics

Threads
1,223,098
Messages
6,170,099
Members
452,301
Latest member
QualityAssurance

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top