How to 'no-fill' empty cell that has been highlighted before?

Joined
Jul 9, 2014
Messages
11
Reaction score
0
Points
0
i have code like below. This code will highlight the cell if meet condition. But it also highlight empty cell too.
My problem is to 'no-fill' the highlighted empty cell.
Below is the code sample



If processrow > 0 Then

yearidx = Year(.Cells(i, "B").value) - Application.Min(target.Rows(1))
monthidx = Month(.Cells(i, "B").value)
If Application.CountA(target.Rows(processrow)) > 1 Then

processrow = processrow + 1
target.Rows(processrow).Insert
End If

targetcol = yearidx * 12 + monthidx + 1
target.Cells(processrow, targetcol).value = .Cells(i, "C").value
target.Cells(processrow, targetcol).Interior.ColorIndex = 3



End If
 

p45cal

Super Moderator
Staff member
Joined
Dec 16, 2012
Messages
2,170
Reaction score
12
Points
38
Excel Version(s)
365
change last line above to:
Code:
If Len(.Cells(i, "C").Value) > 0 Then target.Cells(processrow, targetcol).Interior.ColorIndex = 3
 

p45cal

Super Moderator
Staff member
Joined
Dec 16, 2012
Messages
2,170
Reaction score
12
Points
38
Excel Version(s)
365
oops, that should have been:
Code:
If Len(.Cells(i, "C").Value) > 0 Then
  target.Cells(processrow, targetcol).Interior.ColorIndex = 3
Else
  target.Cells(processrow, targetcol).Interior.ColorIndex = xlNone
End If
 
Top