I am trying to run a search for all cells in a spreadsheet that have a
specific background color. The good news is I can do it and view the list of
all formatted cells. I would like to then copy the contents of these cells
and place them on another sheet. However, I am having trouble copying the
contents and moving them. Can anyone provide any suggestions?
Thanks
How about a macro?
Option Explicit
Sub testme()
Dim CurWks As Worksheet
Dim RptWks As Worksheet
Dim FoundCell As Range
Dim destCell As Range
Dim FirstAddress As String
Application.FindFormat.Clear
With Application.FindFormat.Interior
.ColorIndex = 6 'whatever you want here!
End With
Set CurWks = Worksheets(quot;sheet1quot;)
Set RptWks = Worksheets.Add
Set destCell = RptWks.Range(quot;a1quot;)
With CurWks.UsedRange
Set FoundCell = .Cells.Find(What:=quot;quot;, _
After:=.Cells(.Cells.Count), _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=True)
If FoundCell Is Nothing Then
'do nothing
MsgBox quot;not found!quot;
Else
FirstAddress = FoundCell.Address
Do
FoundCell.Copy _
Destination:=destCell
destCell.Offset(0, 1).Value = FoundCell.Address(0, 0)
Set destCell = destCell.Offset(1, 0)
Set FoundCell = .Cells.Find(What:=quot;quot;, _
After:=FoundCell, _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=True)
Loop While Not FoundCell Is Nothing _
And FoundCell.Address lt;gt; FirstAddress
End If
End With
End Sub
The .findnext() stuff seemed to forget about the searchformat parm.
If you're new to macros, you may want to read David McRitchie's intro at:
www.mvps.org/dmcritchie/excel/getstarted.htm
john mcmichael wrote:
gt;
gt; I am trying to run a search for all cells in a spreadsheet that have a
gt; specific background color. The good news is I can do it and view the list of
gt; all formatted cells. I would like to then copy the contents of these cells
gt; and place them on another sheet. However, I am having trouble copying the
gt; contents and moving them. Can anyone provide any suggestions?
gt;
gt; Thanks
--
Dave Peterson
- Aug 28 Tue 2007 20:39
search excel for cells with a color
close
全站熱搜
留言列表
發表留言