Omgili, forum search, forums search, search forums, discussion search,discussions search, search discussions, board search, boards search, search boards
  Advanced Search

Replaced text count

On Fri, 29 May 2009 02:49:01 -0700, Bartosz <...@Mo2.pl

Hello,

I made macro wich repace texts in other one in many Excel files (using
replace method). I think about making report after to know how many changes
was made in each files:

text to replace new text
aaaa bbbbb
cc XXXXX
.....

Files:
1.xls, 2.xls

Repor:
File sheet text to replace new text count
1.xls Sheet1 aaaa bbbbb 3
1.xls Sheet1 cc XXXXX 3
1.xls Sheet2 aaaa bbbbb 0
1.xls Sheet2 cc XXXXX 34
...
2.xls Sheet1 aaaa bbbbb 3
2.xls Sheet1 cc XXXXX 3
...
Count column contan number of changes as it is show after "hand made"
replace (Ctr+H).

Bartosz



On Fri, 29 May 2009 04:01:01 -0700, Bartosz <...@Mo2.pl

„Bartosz” pisze:

I use this code in macro:
For Each ws In Worksheets
Worksheets(ws.Name).Activate
For X = 1 To ilelinii - 1
Cells.Replace What:=strTabela(X, 1),
Replacement:=strTabela(X, 2), LookAt:=dopasowanie, SearchOrder _
:=xlByRows, MatchCase:=False, SearchFormat:=False,
ReplaceFormat:=False
Next X
Next ws

strTabela(X, 2) is table with texts to change and new one.
dopasowanie is xlWhole/xlPart define by user

Probably to count chages I will need another one.

Bartosz

On Fri, 29 May 2009 04:09:01 -0700, OssieMac <...@discussions.microsoft.com

No sure how much help you want here but here is an example of establishing
the number of replacements.

It involves counting the number of strings to be replaced before actually
making the replacements. (I don't know of any way of returning the number of
replacements from the Replace code.)

I have assumed that you can make a table of the results returned in the
variable dblNumberReplaces.

With Sheets("Sheet1")

dblNumberReplaces = WorksheetFunction _
.CountIf(.Cells, strToReplace)

.Cells.Replace What:=strToReplace, _
Replacement:=strReplacement, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
MatchCase:=True, _
SearchFormat:=False, _
ReplaceFormat:=False
End With

--
Regards,

OssieMac


On Fri, 29 May 2009 05:21:01 -0700, Bartosz <...@Mo2.pl

„OssieMac” pisze:
It will work fine, but only with parametr LookAt:=xlWhole, but when I use
LookAt:=xlPart count number and replaced number will be differend.
I try with:

dblNumberReplaces = WorksheetFunction.CountIf(.Cells, "*"&strToReplace&"*")

but with two strings in one cell (like Cells(x,y).Value = "strToReplace
123456 strToReplace") this cell is count as one.

Regards,
Bartosz

On Fri, 29 May 2009 22:11:01 -0700, OssieMac <...@discussions.microsoft.com

I don't often give up but I'm giving up on this one. I thought I might be
able to do what you want but too many other problems kept raising their ugly
head.

--
Regards,

OssieMac

> Bartosz

On Sun, 31 May 2009 22:45:02 -0700, Bartosz <...@Mo2.pl

"OssieMac” pisze:

Thanks anyway!
I don't want to change my macro, but I will need to do this.
I will change replace function to find in loop from Ms Help:

With Worksheets(1).Range("a1:a500")
Set c = .Find(2, lookin:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
Do
c.Value = 5
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address < End If
End With

Inside this do ... loop I can cound changes in files.

Best Regards,
Bartosz

Discussion Title: Replaced text count
Title Keywords: Replaced  text  count