
Signature
Wigi
http://www.wimgielis.be = Excel/VBA, soccer and music
This may, or may not, do what you want...there is a requirement that the cell
be colored by applying the 'Fill Color' tool (i.e., not conditional
formatting colors). Also, I am assuming that the cell's interior color is
red (i.e. 3)
http://www.mvps.org/dmcritchie/excel/colors.htm
Change the color to suit your needs:
Sub colorcopier()
Dim i As Long
k = 1
Set r = ActiveSheet.UsedRange
nLastRow = r.Rows.count + r.Row - 1
For i = 1 To nLastRow
If is_it_red(i) Then
Set rc = Cells(i, 1).EntireRow
Set rd = Sheets("Copy If Red #2").Cells(k, 1)
rc.Copy rd
k = k + 1
End If
Next
End Sub
Function is_it_red(i As Long) As Boolean
is_it_red = False
For j = 1 To Columns.count
If Cells(i, j).Interior.ColorIndex = 3 Then
is_it_red = True
Exit Function
End If
Next
End Function
Regards,
Ryan---

Signature
RyGuy
> The code depends on a few things:
>
[quoted text clipped - 12 lines]
> > for and identifying the background color cells), but how can I code to
> > copy/paste the values in specific cells?
Jamal - 25 Jul 2008 19:33 GMT
Hi Ryan,
Thanks for your reply, but I get a run time error 9 (Subscript out of range)
for the line:
Set rd = Sheets("Copy If Red #2").Cells(k, 1)
I modified the code to search for yellow, and it is as follows:
Sub colorcopier()
Dim i As Long
k = 1
Set r = ActiveSheet.UsedRange
nLastRow = r.Rows.Count + r.Row - 1
For i = 1 To nLastRow
If is_it_yellow(i) Then
Set rc = Cells(i, 1).EntireRow
Set rd = Sheets("Copy if Yellow #2").Cells(k, 1)
rc.Copy rd
k = k + 1
End If
Next
End Sub
Function is_it_yellow(i As Long) As Boolean
is_it_yellow = False
For j = 1 To Columns.Count
If Cells(i, j).Interior.ColorIndex = 6 Then
is_it_yellow = True
Exit Function
End If
Next
End Function
Also, I believe the code you wrote would copy the entire row, but I am only
looking for specific cells to be copied (say, cells in column A, G, and M)
Any suggestions on how this can be done?
Thanks!
> This may, or may not, do what you want...there is a requirement that the cell
> be colored by applying the 'Fill Color' tool (i.e., not conditional
[quoted text clipped - 48 lines]
> > > for and identifying the background color cells), but how can I code to
> > > copy/paste the values in specific cells?