Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 59
Default Macro to Update all worksheets

Hi, I am having an issue with this macro actually updating all the
sheets in a workbook. I am trying to do a find/replace for each tab in
a workbook - should be simple right?

Here's my code

Dim WS As Worksheet
For Each WS In ActiveWorkbook.Worksheets
Range("A1").Select
Cells.Replace What:="FactorName", Replacement:=MyFactor
Next WS

It find's and replaces the first sheet just fine, and as I step
through the code it repeats as many times as their are worksheets (10
times, once for each worksheet) but for only the first sheet is
updated. Not sure what's going on.

I'm sure this is simple, thanks for your help.
Brian
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Macro to Update all worksheets

Hi,

Try this, You must qualify the range by using WS.cells. Note that MyFactor
is a variable and your replacing a text value. If the variable is given a
value you will simply end up with empty cells. Did you really mean

WS.Cells.Replace What:="FactorName", Replacement:="MyFactor"

Dim WS As Worksheet
For Each WS In ActiveWorkbook.Worksheets
WS.Cells.Replace What:="FactorName", Replacement:=MyFactor
Next WS

Mike


"Bongard" wrote in message
...
Hi, I am having an issue with this macro actually updating all the
sheets in a workbook. I am trying to do a find/replace for each tab in
a workbook - should be simple right?

Here's my code

Dim WS As Worksheet
For Each WS In ActiveWorkbook.Worksheets
Range("A1").Select
Cells.Replace What:="FactorName", Replacement:=MyFactor
Next WS

It find's and replaces the first sheet just fine, and as I step
through the code it repeats as many times as their are worksheets (10
times, once for each worksheet) but for only the first sheet is
updated. Not sure what's going on.

I'm sure this is simple, thanks for your help.
Brian



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default Macro to Update all worksheets

Try it with this slight mod.

Dim WS As Worksheet
For Each WS In ActiveWorkbook.Worksheets
With WS
.Cells.Replace What:="FactorName", Replacement:=MyFactor
End With
Next WS




"Bongard" wrote in message
...
Hi, I am having an issue with this macro actually updating all the
sheets in a workbook. I am trying to do a find/replace for each tab in
a workbook - should be simple right?

Here's my code

Dim WS As Worksheet
For Each WS In ActiveWorkbook.Worksheets
Range("A1").Select
Cells.Replace What:="FactorName", Replacement:=MyFactor
Next WS

It find's and replaces the first sheet just fine, and as I step
through the code it repeats as many times as their are worksheets (10
times, once for each worksheet) but for only the first sheet is
updated. Not sure what's going on.

I'm sure this is simple, thanks for your help.
Brian



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 56
Default Macro to Update all worksheets

Change "Range("A1").Select" and the "cells" line to one line:
ws.Cells.Replace What:="FactorName", Replacement:=MyFactor

This is a classic VBA problem because "Range" by itself automatically
refers to the active sheet.
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 59
Default Macro to Update all worksheets

Thanks to the prompt response from everyone. This definitely makese
sense and I can see now why it wasn't working. I knew it would be an
easy fix.

Thanks again,
Brian


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
Update worksheets Sinner Excel Programming 1 February 23rd 08 12:45 PM
how do I get a macro to update dates in multiple worksheets? BB_XLNovice[_2_] Excel Programming 0 April 27th 07 06:18 PM
Macro to update all worksheets in workbook Christine[_7_] Excel Programming 2 July 4th 04 02:59 PM
Can an add-in macro update a worksheets Worksheet_Change function? strataguru Excel Programming 1 October 4th 03 07:06 PM


All times are GMT +1. The time now is 01:30 AM.

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"