![]() |
|
#1
|
|||
|
|||
![]()
hi, thank u very much for your reply
![]() Yes, they are terminated by "/", but not for the ending of each data. As you can see, after the end of SO1, there's no "/" Note: ^t ---> tab character S01=02^t45.01.39.05x245x201x939x905x01x45x39x05x37 x73/01.30.66.00.28.64x74x45x5x10 L01=03^t0266X2/2066X2/6066X2/6766X2/266X3/066X3/766X3/66X10/15X5/51X5/11X5/16X5/516X5/99X5 L02=04^t06X5.60.5.2.5/20X5.5.5.50.5.3.3 B01=05 62.58.75.85.26.08.80.45.42X2X54X72X15X299X8X15X63X 57X5/50X7X56X45X30X90X4/06.76.16.86.24X4/439.39X6/49.94.15.51X100 B02=07^t29.92.26.62.36.63.46.64.59X3x95x6/278.295.241.277x244X248X2/78.95.85.41.77.44X4x53X2/578.578.539x2/78.76.39x4/13.25.52.28.82.18.81X6 They should be like this: S01=02^t45.01.39.05x245.201.939.905.01.45.39.05.37 .73/01.30.66.00.28.64x74.45.5.10 L01=03^t0266x2/2066x2/6066x2/6766x2/266x3/066x3/766x3/66x10/15x5/51x5/11x5/16x5/516x5/99x5 L02=04^t06x5.60.5.2.5/20x5.5.5.50.5.3.3 B01=05 62.58.75.85.26.08.80.45.42x2.54.72.15.299.8.15.63. 57.5/50.7.56.45.30.90.4/06.76.16.86.24x4/439.39x6/49.94.15.51x100 B02=07^t29.92.26.62.36.63.46.64.59x3.95.6/278.295.241.277x244.248.2/78.95.85.41.77.44x4.53.2/578.578.539x2/78.76.39x4/13.25.52.28.82.18.81x6 I've the macro in Excel for the same functions, but of course it doesn't work in Word. The code: Code:
Sub test() Dim rng As Range, r As Range, x, i As Long On Error Resume Next Set rng = Cells.SpecialCells(2) On Error GoTo 0 If rng Is Nothing Then Exit Sub With CreateObject("vbscript.regexp") .IgnoreCase = True .Pattern = "(.*)(x)(.*)(\2)(.*)" For Each r In rng x = Split(LCase$(r.Value), "/") For i = 0 To UBound(x) Do While .test(x(i)) x(i) = .Replace(x(i), "$1x$3.$5") Loop Next r.Value = Join$(x, "/") Next End With Set rng = Nothing End Sub https://www.msofficeforums.com/attac...1&d=1334926607 https://www.msofficeforums.com/attac...1&d=1334926817 Thanks a lot Macropod ![]() Regards, Jasa |
#2
|
||||
|
||||
![]() Quote:
Code:
Sub Demo() Application.ScreenUpdating = False Dim Rng As Range With ActiveDocument.Range With .Find .ClearFormatting .Replacement.ClearFormatting .Text = "([0-9])[Xx]" .Replacement.Text = "" .Forward = True .Wrap = wdFindStop .Format = False .MatchWildcards = True .Execute End With Do While .Find.Found Set Rng = .Duplicate .Duplicate.Characters.Last = "x" With Rng .Start = .Duplicate.End + 1 Do If Not .Characters.Last Like "[/" & vbCr & "]" Then .End = .End + 1 Else Exit Do End If Loop If InStr(1, .Text, "x", vbTextCompare) > 0 Then .Text = Replace(.Text, "x", ".", 1, , vbTextCompare) End With .Start = Rng.End .Find.Execute Loop End With Application.ScreenUpdating = True End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] Last edited by macropod; 04-20-2012 at 07:58 PM. Reason: Code Enhancement to handle upper/lower case 'x' replacement |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
powerdrum | Word VBA | 2 | 12-08-2011 05:06 PM |
Why the "Headings" are appearing in capital letters in the Table of contents? | Jamal NUMAN | Word | 1 | 05-31-2011 08:31 AM |
Search for paras beginging with a lower case | MShroff | Word | 1 | 10-19-2010 06:41 AM |
![]() |
leroytrolley | Excel | 2 | 12-05-2008 02:05 AM |
Upper to lower case | jd | Excel | 1 | 04-28-2006 07:40 AM |