Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-18-2012, 01:33 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 VBA code for changing capital letters become lower

Hi, I have some problems here. I have to change


1. the capital letter of "X" becomes lower letter "x" and
2. the "x" after first "x" becomes dot "."
Would you mind to help me?

For the example:
A2^t4391.4586X5.5.5/57x20/885.85x10/61x12/64.58x8/8328.2883x2x2x5/64.11.47x5/230.30.249.49x30/130.630.30.93.57.230x5

As you see the red one should be 4391.4586x5.5.5 and 8328.2883x2.2.5

For another example:
B37^t739.93.12x2/39.99x3/89.98x12/249.49.94.230.30x5/2989.8929X3X3X3/128x2.3/46x2/2165x5.5.5/0131.131.113.031.013x10/3

As you see the red one should be 2989.8929x3.3.3

I'm using Windows7 for notebook and XP for PC, Word 2007
Any help would be great.





Regards


Jasa
Reply With Quote
  #2  
Old 04-18-2012, 04:16 AM
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: 21,962
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

Hi Jasa,

You can do it without a macro, using a wildcard Find/Replace, where:
Find = ([0-9])[Xx]([0-9])[Xx.]([0-9])[Xx.]([0-9])
Replace= \1x\2.\3.\4
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 04-19-2012, 09:46 PM
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

Quote:
Originally Posted by macropod View Post
Hi Jasa,

You can do it without a macro, using a wildcard Find/Replace, where:
Find = ([0-9])[Xx]([0-9])[Xx.]([0-9])[Xx.]([0-9])
Replace= \1x\2.\3.\4
Hi, thanks a lot for helping me. Yeah, you are totally right and it can be done with Find and Replace. But, sometimes the data has 4 or more of "x".
Ex:
B3^t739X93.12.2.49.94 ---> 739x93.12.2.49.94
B4^t249.49.94x230x30x5x2165x5x5 ---> 249.49.94x230.30.5.2165.5.5

Would you mind to help? maybe it's better in macro Thank u so much



Regards,


Jasa
Reply With Quote
  #4  
Old 04-19-2012, 11:33 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: 21,962
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

Hi Jasa,

It would be helpful if you have the full details up front. Had I written a macro for this, I would not have coded it to work with anything other than what you specified. Indeed, the macro would have been nothing more than a macro version of the wildcard Find/Replace I posted - it certainly wouldn't have catered for variable length sequences of sequences where there is more than one digit in the numbers interspersed by the 'x' characters as suggested in the example in your latest post.

Before coding a macro to handle variable sequence lengths, I also need to know whether they always terminate in a '/' character as indicated in your first post's examples.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
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, 10 views)
File Type: xlsm Sample.xlsm (15.9 KB, 6 views)
Reply With Quote
  #6  
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: 21,962
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
  #7  
Old 05-02-2012, 12:10 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

my goodness! It works.. It's a great celebration for me. Thanks a lot macropod.

You're brilliant!

Thanks a lot macropod..! Thank u for helping me!
Totally BRILLIANT!!



Best reagrds,


Jasa
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 10:51 PM.


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