Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #7  
Old 05-25-2014, 12:16 AM
macropod's Avatar
macropod macropod is offline Find max number of same subsequent character Windows 7 32bit Find max number of same subsequent character Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Shifting the goal posts, eh? You could turn it into a function, thus:
Code:
Sub Demo()
Application.ScreenUpdating = False
Dim i As Long, j As Long, Rng As Range
Set Rng = ActiveDocument.Range
With ActiveDocument.Range
  With .Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = ""
    .Replacement.Text = ""
    .Format = True
    .Style = "Normal"
    .Forward = True
    .Wrap = wdFindStop
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    .Execute
  End With
  Do While .Find.Found
    If InStr(.Text, " ") > 0 Then
      i = GetMaxSpaces(.Text)
      If i > j Then j = i
    End If
    If .End = Rng.End Then Exit Do
    .Collapse wdCollapseEnd
    .Find.Execute
  Loop
End With
Application.ScreenUpdating = True
MsgBox "The maximum space sequence is: " & j
End Sub
 
Function GetMaxSpaces(StrTxt As String)
Dim StrTmp As String, i As Long
StrTmp = " "
While InStr(StrTxt, StrTmp) > 0
    StrTmp = StrTmp & " "
    i = i + 1
Wend
GetMaxSpaces = i
End Function
Simply change 'Normal' to your Style name.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Find max number of same subsequent character Help!! find two number recurring numbers in row?? carrolld2 Excel 5 06-28-2014 05:43 PM
Find max number of same subsequent character macro to find a character and insert space so autocorrect will expand redzan Word VBA 3 05-22-2014 04:22 PM
Find max number of same subsequent character Help with the "find and replace" option; character problem martinn4 Word 3 02-20-2014 03:52 AM
Find max number of same subsequent character Conditional tied to trying to find a " " space character Dart82 Word VBA 3 10-04-2013 01:47 PM
Concatenated data in subsequent rows doorsgirl Excel 4 09-15-2011 10:37 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:53 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft