Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
john mcmichael
 
Posts: n/a
Default search excel for cells with a color

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
  #2   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson
 
Posts: n/a
Default search excel for cells with a color

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("sheet1")
Set RptWks = Worksheets.Add

Set destCell = RptWks.Range("a1")

With CurWks.UsedRange
Set FoundCell = .Cells.Find(What:="", _
After:=.Cells(.Cells.Count), _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=True)
If FoundCell Is Nothing Then
'do nothing
MsgBox "not found!"
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:="", _
After:=FoundCell, _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=True)
Loop While Not FoundCell Is Nothing _
And FoundCell.Address < 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:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

john mcmichael wrote:

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


--

Dave Peterson
Reply
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
Color coding the excel sheets Shane Excel Discussion (Misc queries) 3 November 1st 05 04:51 PM
TRYING TO SET UP EXCEL SPREADSHEET ON MY COMPUTER MEGTOM New Users to Excel 5 October 27th 05 03:06 AM
Excel Range Value issue (Excel 97 Vs Excel 2003) Keeno Excel Discussion (Misc queries) 2 June 13th 05 02:01 PM
Excel Object copied to Word not printing in color dmotika Excel Discussion (Misc queries) 0 May 26th 05 04:40 PM
Changing color palette for Excel 2002 Glenn Chung Excel Discussion (Misc queries) 1 May 5th 05 08:22 PM


All times are GMT +1. The time now is 07:31 PM.

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

About Us

"It's about Microsoft Excel"