What's Wrong?

  • Thread starter Thread starter Pam
  • Start date Start date
P

Pam

I'm trying to color the background of a row if a certain
set of conditions exists.

I don't know what's wrong with this:

For i = rng.Row To 1 Step -1

If Cells(i, 9).Value = Cells(i - 1, 10).Value _
And Cells(i, 10).Value = Cells(i - 1, 9).Value _
And Cells(i, 1).Value = Cells(i - 1, 1).Value _
And Cells(i, 2).Value = Cells(i - 1, 2).Value _
Then Cells(i, 1).EntireRow.Interior.ColorIndex = 35
end if
Next

I've tried taking out the "end if", including just "end",
but nothing works??? I get a 1004 error.
 
For i = rng.Row To 1 Step -1

If Cells(i, 9).Value = Cells(i - 1, 10).Value _
And Cells(i, 10).Value = Cells(i - 1, 9).Value _
And Cells(i, 1).Value = Cells(i - 1, 1).Value _
And Cells(i, 2).Value = Cells(i - 1, 2).Value _
Then
Cells(i, 1).EntireRow.Interior.ColorIndex = 35
end if
Next

or

For i = rng.Row To 1 Step -1

If Cells(i, 9).Value = Cells(i - 1, 10).Value _
And Cells(i, 10).Value = Cells(i - 1, 9).Value _
And Cells(i, 1).Value = Cells(i - 1, 1).Value _
And Cells(i, 2).Value = Cells(i - 1, 2).Value _
Then Cells(i, 1).EntireRow.Interior.ColorIndex = 35

Next

Both compile fine for me. However, I assume this is part of a larger
procedure, so it could be affected by code I can not see.
 

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