Find next cell

  • Thread starter Thread starter Martin Wheeler
  • Start date Start date
M

Martin Wheeler

XL 2000

The code below is supposed to colour yellow all cells in the range that fill
the criteria. But it is only working on the first applicable cell and not
going on to the next.
I have scavenged the code from another app and cannot see why it is not
repeating. Any help would be greatly appreciated.
Ta,
Martin
Public Sub FiftyKYellow(wks As Worksheet)
Application.ScreenUpdating = False
On Error Resume Next
With wks
If .Range("G1").Value > 50000 Then
For Each P In .Range("P7:P31")
If P.Value < -0.195 Then
Set L = P
With L.Interior
.ColorIndex = 6
.Pattern = xlSolid
End With
End If
Exit For
Next
End If
Application.ScreenUpdating = True
End With
End Sub
 
Hi Steve,
Thanks - It works!
I'm always amazed when that happens
Ta,
Martin
 
Martin

the Exit For between the For... and the Next won't help.

Sub call50k()
FiftyKYellow ActiveSheet
End Sub

Public Sub FiftyKYellow(wks)
Dim P As Range
Application.ScreenUpdating = False
On Error Resume Next
With wks
If .Range("G1").Value > 50000 Then
For Each P In .Range("P7:P31")
If P.Value < -0.195 Then
With P.Interior
.ColorIndex = 6
.Pattern = xlSolid
End With
End If
Next
End If
Application.ScreenUpdating = True
End With
End Sub


Regards

Trevor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top