Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Multiple Ranges and Find/Replace

Could this be shortened to one block with something like, ("clr1",
"clr2", ..). Taking it a step further, could the block be replaced
with a single find/replace statement? I'm having trouble getting the
find/replace syntax correct.

For Each cell In Sheet1.range("clr1").Cells
If cell = "0" Then cell.Formula = "=NA()"
Next cell

For Each cell In Sheet1.range("clr2").Cells
If cell = "0" Then cell.Formula = "=NA()"
Next cell

For Each cell In Sheet1.range("clr3").Cells
If cell = "0" Then cell.Formula = "=NA()"
Next cell

For Each cell In Sheet1.range("clr4").Cells
If cell = "0" Then cell.Formula = "=NA()"
Next cell
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Multiple Ranges and Find/Replace

Maybe something like:

Dim myRng As Range

With Sheet1
Set myRng = Union(.Range("clr1"), .Range("clr2"), .Range("clr3"))
End With

myRng.Replace what:=0, replacement:="=Na()", _
lookat:=xlWhole, searchorder:=xlByRows, MatchCase:=False

(I got lazy and stopped after clr3.)



Spare wrote:

Could this be shortened to one block with something like, ("clr1",
"clr2", ..). Taking it a step further, could the block be replaced
with a single find/replace statement? I'm having trouble getting the
find/replace syntax correct.

For Each cell In Sheet1.range("clr1").Cells
If cell = "0" Then cell.Formula = "=NA()"
Next cell

For Each cell In Sheet1.range("clr2").Cells
If cell = "0" Then cell.Formula = "=NA()"
Next cell

For Each cell In Sheet1.range("clr3").Cells
If cell = "0" Then cell.Formula = "=NA()"
Next cell

For Each cell In Sheet1.range("clr4").Cells
If cell = "0" Then cell.Formula = "=NA()"
Next cell


--

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
Multiple Criteria Find & Replace Alfred Excel Worksheet Functions 3 October 21st 09 07:13 PM
multiple find and replace Andre Excel Worksheet Functions 1 May 26th 09 02:31 PM
Multiple find mulitple replace spaceage Excel Worksheet Functions 1 March 29th 07 11:42 AM
Find/Replace in multiple worksheets Lynn Excel Discussion (Misc queries) 1 March 22nd 07 04:17 PM
Multiple Find and Replace in one function [email protected] Excel Worksheet Functions 4 September 11th 06 03:16 AM


All times are GMT +1. The time now is 06:27 AM.

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"