Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-20-2012, 06:02 AM
Jasa P Jasa P is offline VBA code for changing capital letters become lower Windows XP VBA code for changing capital letters become lower Office 2007
Novice
VBA code for changing capital letters become lower
 
Join Date: Apr 2012
Posts: 13
Jasa P is on a distinguished road
Default

hi, thank u very much for your reply I've tried to use the Find & Replace that you gave me, but It doesn't work and I don't know what is wrong.



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
I attached some sample files here:
https://www.msofficeforums.com/attac...1&d=1334926607
https://www.msofficeforums.com/attac...1&d=1334926817
Thanks a lot Macropod


Regards,


Jasa
Attached Files
File Type: docx Sample.docx (12.0 KB, 12 views)
File Type: xlsm Sample.xlsm (15.9 KB, 8 views)
Reply With Quote
  #2  
Old 04-20-2012, 07:36 PM
macropod's Avatar
macropod macropod is offline VBA code for changing capital letters become lower Windows 7 64bit VBA code for changing capital letters become lower 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

Quote:
Originally Posted by Jasa P View Post
I've tried to use the Find & Replace that you gave me, but It doesn't work and I don't know what is wrong.
That's hardly surprising, since the data in your latest post are quite different to what you originally asked for help with. Try the following macro:
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
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA code for changing capital letters become lower Converts the words to actual All Capital Letters not workin macro?? 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
VBA code for changing capital letters become lower Code for Changing Cell Backgrounds leroytrolley Excel 2 12-05-2008 02:05 AM
Upper to lower case jd Excel 1 04-28-2006 07:40 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:29 AM.


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