Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cell color

Status
Not open for further replies.

leroiv

Programmer
Mar 29, 2007
8
RO
Hi! I have the code below :
Code:
Sub PopulareCelule()
    Dim k As Integer
    Dim l As Integer
    k = ActiveCell.Column
    l = ActiveCell.Row
    For i = k To 35
    If ActiveCell.Interior.ColorIndex = 4 Then
        Cells(l, i).Value = "yes"
    Else
        Cells(l, i).Value = "no"
    End If
    Next
End Sub
My problem is that when I run the macro , in the range of cells (let's say E6:AI6) , it fills only with a single value ("yes" or "no") even if in the range are cells with another color! Can you help me please? thank you!
 
The active cell is not changing. Therefore, If ActiveCell.Interior.ColorIndex = 4 will only have a single state. Perhaps you want If [red]cells(l,i)[/red].Interior.ColorIndex = 4?

_________________
Bob Rashkin
 



Hi,

I advise against using ActiveCell, Select method to navigate thru code.
Code:
Sub PopulareCelule()
   dim rng as range

   for each rng in range("E6:AI6")
      If rng.Interior.ColorIndex = 4 Then
        rng.Value = "yes"
      Else
        rng.Value = "no"
      End If
    Next
   next

End Sub

Skip,

[glasses] [red][/red]
[tongue]
 
Yes, that's it! Thank you Bong and Skip!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top