LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default copy row based on color

Hi hshayh0rn

Try this (untested)

Sub testme2()

Dim myCell As Range
Dim newWks As Worksheet
Dim curWks As Worksheet
Dim LastRow As Long
Dim LastCol As Long
Dim iRow As Long
Dim iCol As Long
Dim oRow As Long
Dim rng As Range
Dim myColorIndex As Long

Set curWks = Worksheets("2006 Scheduled Activities")
Set newWks = Worksheets("sheet3")

myColorIndex = 6
oRow = 1
With curWks
With .UsedRange
LastRow = .Rows(.Rows.Count).Row
End With

For iRow = 1 To LastRow
If IsError(.Cells(iRow, "A").Value) Then
'Do nothing, This avoid a error if there is a error in the cell

ElseIf .Cells(iRow, "A").Interior.ColorIndex = myColorIndex Then
If rng Is Nothing Then
Set rng = .Cells(iRow, "A")
Else
Set rng = Application.Union(rng, .Cells(iRow, "A"))
End If
End If

Next iRow
End With

If Not rng Is Nothing Then rng.EntireRow.Copy newWks.Range("A1")

End Sub



--
Regards Ron de Bruin
http://www.rondebruin.nl


"hshayh0rn" wrote in message ...
I would like to look at all of the rows in column A and determine if the
color = "6" and if the color index is 6 then copy that entire row to another
sheet. I believe I have code that will check for the color but I'm not sure
how to then copy the row to the other sheet. Also, I either need to amend the
destination sheet or replace the contents of the sheet all together. I can
not have duplicates on the dest sheet. Here is what I have so far:

Sub testme()

Dim myCell As Range
Dim newWks As Worksheet
Dim curWks As Worksheet
Dim LastRow As Long
Dim LastCol As Long
Dim iRow As Long
Dim iCol As Long
Dim oRow As Long
Dim rng As Range
Dim myColorIndex As Long

Set curWks = Worksheets("2006 Scheduled Activities")
Set newWks = Worksheets("sheet3")

myColorIndex = 6
oRow = 1
With curWks
With .UsedRange
LastRow = .Rows(.Rows.Count).Row
End With

For iRow = 1 To LastRow
If .Cells(iRow, "A").Interior.ColorIndex = myColorIndex Then
'
'need the code that would go here to copy the entire row to sheet3 is the
row matches color index 6
'

End If
'End If
Next iRow
End With
End Sub




 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Change tab color based on current color of a cell MarkT Excel Discussion (Misc queries) 0 May 22nd 08 05:46 PM
change fill color of a range of cells based on color of a cell? DarMelNel Excel Programming 0 March 2nd 06 06:35 PM
Copy Color Formats Based On Column Date Values Naji Excel Discussion (Misc queries) 0 January 11th 06 09:06 PM
copy and paste to another sheet based in cell color nat3ten Excel Programming 7 July 8th 05 11:14 PM
Browse Forms Controls and change TextBox color based on cell color StefanW Excel Programming 2 November 21st 04 07:06 PM


All times are GMT +1. The time now is 01:12 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"