Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Combine 2 VBA Replacements | Excel Discussion (Misc queries) | |||
howto convert a number into words like 10 to ten | New Users to Excel | |||
Count rows and insert number to count them. | Excel Discussion (Misc queries) | |||
Number count - postcodes and need to count the numbers of tim... | Excel Discussion (Misc queries) | |||
Stop excel from reporting replacements | Excel Discussion (Misc queries) |