Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 599
Default HowTo Count number of replacements

Keith

I don't think looping through the cells would be that bad. Like this

Sub myrepl2()

Dim rFound As Range
Dim sFirstAdd As String
Dim lRepCnt As Long

Set rFound = Sheet1.Cells.Find("too")

If Not rFound Is Nothing Then
sFirstAdd = rFound.Address

Do
lRepCnt = lRepCnt + 1
Set rFound = Sheet1.Cells.Find("too", rFound)
Loop Until rFound.Address = sFirstAdd
End If

Sheet1.Cells.Replace "too", "two"
MsgBox lRepCnt

End Sub

Another way would be to use the change event, like this in a standard module

Public lReplaceCnt As Long
Public bReplacing As Boolean

Sub myrepl()

lReplaceCnt = 0
bReplacing = True
Sheet1.Cells.Replace "two", "too"
bReplacing = False

MsgBox lReplaceCnt

End Sub

And this in the Sheet's module

Private Sub Worksheet_Change(ByVal Target As Range)

If bReplacing Then
lReplaceCnt = lReplaceCnt + 1
End If

End Sub

--
Dick Kusleika
MVP - Excel
Excel Blog - Daily Dose of Excel
www.dicks-blog.com

"Keith Harris" wrote in message
...
Hi,

I have a simple macro which will replace one character with another:

ActiveSheet.Cells.Replace "&", "&", xlPart, xlByRows, True

Does anyone know how to return the number of replacements other than
iterating through each cell and counting -- which I imagine would be very
slow.

Thanks for any help.
-Keith



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
Combine 2 VBA Replacements CVinje Excel Discussion (Misc queries) 2 October 16th 09 09:58 AM
howto convert a number into words like 10 to ten kaushik New Users to Excel 7 September 26th 09 09:54 AM
Count rows and insert number to count them. Mex Excel Discussion (Misc queries) 6 August 23rd 06 02:29 AM
Number count - postcodes and need to count the numbers of tim... Mark - Aust Excel Discussion (Misc queries) 1 October 24th 05 10:00 AM
Stop excel from reporting replacements Chris Excel Discussion (Misc queries) 1 January 7th 05 01:37 AM


All times are GMT +1. The time now is 04:29 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"