Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Replaced text count

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Replaced text count



€˛Bartosz€¯ pisze:

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


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
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default Replaced text count

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


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default Replaced text count

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" wrote:

€˛OssieMac€¯ pisze:
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

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

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Replaced text count

"OssieMac€¯ pisze:

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.

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 < firstAddress
End If
End With

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

Best Regards,
Bartosz
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
Accidently replaced a spreadsheet that I did not want replaced T Excel Discussion (Misc queries) 2 June 28th 07 04:52 PM
Some cells have been colored and should be replaced by text basha Excel Worksheet Functions 1 April 20th 07 04:09 PM
Text replaced with # jay_babcock Excel Discussion (Misc queries) 4 October 14th 05 10:28 PM
Why has my cell text been replaced by # characters? sggp Excel Discussion (Misc queries) 1 August 9th 05 09:31 PM
text replaced by #### Sheda Excel Discussion (Misc queries) 2 January 16th 05 03:23 PM


All times are GMT +1. The time now is 07:52 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"