PDA

View Full Version : Solved: Code Not Cycling Workbook



jo15765
01-31-2013, 09:10 AM
I am trying to run this:

Dim ws As Worksheet
For Each Worksheet in ActiveWorkbook.Worksheets
Cells.Replace What:="Hello", Replacement:="", LookAt:=xlWhole, SearchOrder _
:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
Next Worksheet

And it is only searching the 1st worksheet?

EDIT - I am also trying to run this in Excel 2007

Aflatoon
01-31-2013, 10:10 AM
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
ws.Cells.Replace What:="Hello", Replacement:="", LookAt:=xlWhole, SearchOrder _
:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
Next ws

jo15765
01-31-2013, 10:50 AM
That code is not cycling the worksheets either....

jolivanes
01-31-2013, 11:45 AM
This works for me

Sub Replace_Hallo()
Dim ws As Worksheet
For Each WS In Worksheets
WS.Cells.Replace What:="Hello", Replacement:="Hallo", _
LookAt:=xlPart, MatchCase:=False
Next
End Sub

BTW, Aflatoon's works for me

jo15765
01-31-2013, 11:51 AM
Still not working....

jolivanes
01-31-2013, 11:28 PM
Did you read the code?
It will replace "Hello" with "Hello"

Sub Replace_Hallo()
Dim ws As Worksheet
For Each ws In Worksheets
ws.Cells.Replace What:="Hello", Replacement:="Hello", _
LookAt:=xlWhole, MatchCase:=False
Next
End Sub

Change the

Replacement:="Hello"

to


Replacement:=""

jo15765
02-01-2013, 07:19 AM
That got it...Thanks!