Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Using "Find" in a macro


I have been trying to record a macro but when I select and use "Find" i
does not record. Is there any code to plug into a macro that will allo
me to Find and Select cells based on that cells background color the
Copy those cells to another location

--
icetre
-----------------------------------------------------------------------
icetrey's Profile: http://www.excelforum.com/member.php...fo&userid=2032
View this thread: http://www.excelforum.com/showthread.php?threadid=39449

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Using "Find" in a macro

Not based on background color. You will need to loop throught the range of
cells and examine the background color. If the background color is
produced through conditional formatting, then you can't examine that
directly - you have to examine the underlying condition that produces the
color.

--
Regards,
Tom Ogilvy

"icetrey" wrote in
message ...

I have been trying to record a macro but when I select and use "Find" it
does not record. Is there any code to plug into a macro that will allow
me to Find and Select cells based on that cells background color then
Copy those cells to another location?


--
icetrey
------------------------------------------------------------------------
icetrey's Profile:

http://www.excelforum.com/member.php...o&userid=20329
View this thread: http://www.excelforum.com/showthread...hreadid=394499



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Using "Find" in a macro

Are you using xl2002 (or higher).

Then I got something recorded when I tried it manually.

And this is how I modified it:

Option Explicit

Sub testme()

Dim FoundCell As Range
Dim destCell As Range
Dim FirstAddress As String

Application.FindFormat.Clear
With Application.FindFormat.Interior
.ColorIndex = 6
End With

Set destCell = Worksheets("sheet1").Range("a1")

With Worksheets("Sheet2").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
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.

icetrey wrote:

I have been trying to record a macro but when I select and use "Find" it
does not record. Is there any code to plug into a macro that will allow
me to Find and Select cells based on that cells background color then
Copy those cells to another location?

--
icetrey
------------------------------------------------------------------------
icetrey's Profile: http://www.excelforum.com/member.php...o&userid=20329
View this thread: http://www.excelforum.com/showthread...hreadid=394499


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Using "Find" in a macro

Forgot about that enhancement in xl2002 - thanks for the correction.

--
Regards,
Tom Ogilvy

"Dave Peterson" wrote in message
...
Are you using xl2002 (or higher).

Then I got something recorded when I tried it manually.

And this is how I modified it:

Option Explicit

Sub testme()

Dim FoundCell As Range
Dim destCell As Range
Dim FirstAddress As String

Application.FindFormat.Clear
With Application.FindFormat.Interior
.ColorIndex = 6
End With

Set destCell = Worksheets("sheet1").Range("a1")

With Worksheets("Sheet2").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
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.

icetrey wrote:

I have been trying to record a macro but when I select and use "Find" it
does not record. Is there any code to plug into a macro that will allow
me to Find and Select cells based on that cells background color then
Copy those cells to another location?

--
icetrey
------------------------------------------------------------------------
icetrey's Profile:

http://www.excelforum.com/member.php...o&userid=20329
View this thread:

http://www.excelforum.com/showthread...hreadid=394499

--

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
"Find" a wildcard as a place marker and "replace" with original va Eric Excel Discussion (Misc queries) 1 January 27th 09 06:00 PM
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell Steve Kay Excel Discussion (Misc queries) 2 August 8th 08 01:54 AM
Macro to concatenate into "B1" B2 thru B"x" based on new data in "Col A" Dennis Excel Discussion (Misc queries) 0 July 17th 06 02:38 PM
HELP on "left","right","find","len","substitute" functions serene83 Excel Discussion (Misc queries) 5 June 27th 06 02:23 AM


All times are GMT +1. The time now is 10:20 PM.

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"