Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / General Excel Questions / May 2008

Tip: Looking for answers? Try searching our database.

Macro to replace in two worksheets

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
yshridhar - 15 May 2008 04:15 GMT
Hi everybody
The following macro i recorded to replace a value in sheet1 and sheet2.

Sub replas()
   Sheets(Array("Sheet1", "Sheet2")).Select
   Sheets("Sheet2").Activate
   Cells.Replace What:="10", Replacement:="a", LookAt:=xlWhole, SearchOrder _
       :=xlByRows, MatchCase:=False, SearchFormat:=False,
ReplaceFormat:=False
   Range("B1").Select
End Sub

But when i try to run it, it is replacing only in Sheet2.  How to modify it?
Any suggestions. Thanks to all
With regards
Sreedhar
Jim Cone - 15 May 2008 05:14 GMT
Here is one way...
'--
Sub replas_R1()
   Sheets("Sheet1").Cells.Replace What:="10", Replacement:="a", _
   LookAt:=xlWhole, SearchOrder:=xlByRows, MatchCase:=False, _
   SearchFormat:=False, ReplaceFormat:=False
   
   Sheets("Sheet2").Cells.Replace What:="10", Replacement:="a", _
   LookAt:=xlWhole, SearchOrder:=xlByRows, MatchCase:=False, _
   SearchFormat:=False, ReplaceFormat:=False
   
   Range("B1").Select
End Sub
Signature

Jim Cone
Portland, Oregon  USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)

"yshridhar" <yshridhar@discussions.microsoft.com>
wrote in message
Hi everybody
The following macro i recorded to replace a value in sheet1 and sheet2.

Sub replas()
   Sheets(Array("Sheet1", "Sheet2")).Select
   Sheets("Sheet2").Activate
   Cells.Replace What:="10", Replacement:="a", LookAt:=xlWhole, SearchOrder _
       :=xlByRows, MatchCase:=False, SearchFormat:=False,
ReplaceFormat:=False
   Range("B1").Select
End Sub

But when i try to run it, it is replacing only in Sheet2.  How to modify it?
Any suggestions. Thanks to all
With regards
Sreedhar

yshridhar - 15 May 2008 05:29 GMT
Thanks Jim for your suggestion.  Is there any way to do it by selecting all
the sheets at once.
regards
Sreedhar

> Here is one way...
> '--
[quoted text clipped - 9 lines]
>     Range("B1").Select
> End Sub
Jim Cone - 15 May 2008 14:34 GMT
Not that I know of.  
There is very little in VBA that can be accomplished on multiple sheets
with only one iteration.  My experience has been that it consumes all
of your random access memory while trying.
Jim Cone

"yshridhar"
<yshridhar@discussions.microsoft.com>
wrote in message
Thanks Jim for your suggestion.  Is there any way to do it by selecting all
the sheets at once.
regards
Sreedhar

"Jim Cone" wrote:
> Here is one way...
> '--
[quoted text clipped - 9 lines]
>     Range("B1").Select
> End Sub


> "yshridhar" <yshridhar@discussions.microsoft.com>
> wrote in message
[quoted text clipped - 14 lines]
> With regards
> Sreedhar
Gord Dibben - 16 May 2008 01:01 GMT
Sub replas()
   Sheets(Array("Sheet1", "Sheet2")).Select
   Set MySheets = ActiveWindow.SelectedSheets
       For Each ws In MySheets
       ws.Cells.Replace What:="10", Replacement:="a", LookAt:=xlWhole, _
SearchOrder _
       :=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
   Range("B1").Select
   Next ws
   Sheets("Sheet1").Select
End Sub

Gord Dibben  MS Excel MVP

>Thanks Jim for your suggestion.  Is there any way to do it by selecting all
>the sheets at once.
>regards
>Sreedhar
yshridhar - 16 May 2008 05:03 GMT
Thanks Gord.
Regards
Sreedhar

> Sub replas()
>     Sheets(Array("Sheet1", "Sheet2")).Select
[quoted text clipped - 15 lines]
> >regards
> >Sreedhar
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.