PC Review


Reply
Thread Tools Rate Thread

WHAT COULD BE THE REASON FOR VB SCRIPT REGULAR EXPRESION TO WORK O

 
 
=?Utf-8?B?Q0FQVEdOVlI=?=
Guest
Posts: n/a
 
      22nd Jul 2007
DEAR ALL,

I copied about 10 names from the thousands i have and ran the below code
(not my brains but got assistance thanks to Mr. Ron Rosenfield, Gary
student, Jim Thomlinson, Kevin Jones, Mike and Peter Richardson. Pls forgive
me for not following up all your help and assitence on account of my
ignorance of the delay in uploading by google.

By the time I was intimated, the thread has gone cold. Consequently I read
up lot on regexes and sort of got a hang of what the code is about.

Some sugested with inStrRev and split for which I get compile error as my
company provided only excel97.


I AM USING EXCEL97.

FIRST CODE:

This below code did shift the initials to the end of the name but ran once
and does not work again.

Public Sub ConvertNames()
'THIS WORKED FOR ONCE AND SECOND TIME NOT WORKING WHAT COULD BE REASON
Dim RegEx As Object
Dim Cell As Range
Set RegEx = CreateObject("vbscript.regexp")
RegEx.Global = True
RegEx.MultiLine = True
RegEx.IgnoreCase = True
RegEx.Pattern = "^([a-z..]*\.)([a-z]+)$"

For Each Cell In Selection
Cell = RegEx.Replace(Cell, "$2 $1")
Next Cell

End Sub


SECOND CODE:

This below code works fine but the initials goes in the middle if I have two
names.

Option Explicit
Sub MoveInit()

'given by ron rosenfield
Dim c As Range
Dim oRegex As Object
Dim oMatchCollection As Object
Dim i As Long
Const sPattern As String = "(([A-Z]\.\s?)*)(\w+)"

Set oRegex = CreateObject("VBScript.Regexp")
oRegex.Global = True
oRegex.ignorecase = True
oRegex.Pattern = sPattern

For Each c In Selection
c.Offset(0, 1).ClearContents
c.Offset(0, 1).Value = oRegex.Replace(c.Text, "$3 $1")
Next c
End Sub

So pls help me in
A) What must have gone wrong in First code.
B) What must be the code to put the initials at the end if the cell has two
names like
A.S.D.PETER GREG.

Needless to say that I will be watching for all the post continuously all
day long unlike my earlier posts on this same subject.

brgds/captgnvr
 
Reply With Quote
 
 
 
 
Don Guillett
Guest
Posts: n/a
 
      22nd Jul 2007
Please don't type in all CAPS (including subject line) as it is considered
shouting and rude.
Put this in a REGULAR module.
Public Function StrReverse(reverseString As String) As String
Dim i As Long
For i = Len(reverseString) To 1 Step -1
StrReverse = StrReverse & Mid(reverseString, i, 1)
Next i
End Function


--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(E-Mail Removed)
"CAPTGNVR" <(E-Mail Removed)> wrote in message
news:FD95BD93-1CBC-4F20-855B-(E-Mail Removed)...
> DEAR ALL,
>
> I copied about 10 names from the thousands i have and ran the below code
> (not my brains but got assistance thanks to Mr. Ron Rosenfield, Gary
> student, Jim Thomlinson, Kevin Jones, Mike and Peter Richardson. Pls
> forgive
> me for not following up all your help and assitence on account of my
> ignorance of the delay in uploading by google.
>
> By the time I was intimated, the thread has gone cold. Consequently I
> read
> up lot on regexes and sort of got a hang of what the code is about.
>
> Some sugested with inStrRev and split for which I get compile error as my
> company provided only excel97.
>
>
> I AM USING EXCEL97.
>
> FIRST CODE:
>
> This below code did shift the initials to the end of the name but ran once
> and does not work again.
>
> Public Sub ConvertNames()
> 'THIS WORKED FOR ONCE AND SECOND TIME NOT WORKING WHAT COULD BE REASON
> Dim RegEx As Object
> Dim Cell As Range
> Set RegEx = CreateObject("vbscript.regexp")
> RegEx.Global = True
> RegEx.MultiLine = True
> RegEx.IgnoreCase = True
> RegEx.Pattern = "^([a-z..]*\.)([a-z]+)$"
>
> For Each Cell In Selection
> Cell = RegEx.Replace(Cell, "$2 $1")
> Next Cell
>
> End Sub
>
>
> SECOND CODE:
>
> This below code works fine but the initials goes in the middle if I have
> two
> names.
>
> Option Explicit
> Sub MoveInit()
>
> 'given by ron rosenfield
> Dim c As Range
> Dim oRegex As Object
> Dim oMatchCollection As Object
> Dim i As Long
> Const sPattern As String = "(([A-Z]\.\s?)*)(\w+)"
>
> Set oRegex = CreateObject("VBScript.Regexp")
> oRegex.Global = True
> oRegex.ignorecase = True
> oRegex.Pattern = sPattern
>
> For Each c In Selection
> c.Offset(0, 1).ClearContents
> c.Offset(0, 1).Value = oRegex.Replace(c.Text, "$3 $1")
> Next c
> End Sub
>
> So pls help me in
> A) What must have gone wrong in First code.
> B) What must be the code to put the initials at the end if the cell has
> two
> names like
> A.S.D.PETER GREG.
>
> Needless to say that I will be watching for all the post continuously all
> day long unlike my earlier posts on this same subject.
>
> brgds/captgnvr


 
Reply With Quote
 
=?Utf-8?B?Q0FQVEdOVlI=?=
Guest
Posts: n/a
 
      22nd Jul 2007
D/Don
Ur advice reg caps noted. It is bcos of my eyesight and the fonts in these
groups are so small, some important ones i use caps.

I was just waiting for some guidance and as u sugested I tried with the
function. But the whole name also gets reversed. For example A.Z.RED becomes
DER.Z.A.

As I mentioned the second works fine but puts the initials in the middle.
so pls sugest steps to change the name A.S.D.PETER GREG to PETER GREG A.S.D.

For you information some names have space after the initials and in some no
space.

Looking forward to knowing ur advice n thnks for the first step.

"Don Guillett" wrote:

> Please don't type in all CAPS (including subject line) as it is considered
> shouting and rude.
> Put this in a REGULAR module.
> Public Function StrReverse(reverseString As String) As String
> Dim i As Long
> For i = Len(reverseString) To 1 Step -1
> StrReverse = StrReverse & Mid(reverseString, i, 1)
> Next i
> End Function
>
>
> --
> Don Guillett
> Microsoft MVP Excel
> SalesAid Software
> (E-Mail Removed)
> "CAPTGNVR" <(E-Mail Removed)> wrote in message
> news:FD95BD93-1CBC-4F20-855B-(E-Mail Removed)...
> > DEAR ALL,
> >
> > I copied about 10 names from the thousands i have and ran the below code
> > (not my brains but got assistance thanks to Mr. Ron Rosenfield, Gary
> > student, Jim Thomlinson, Kevin Jones, Mike and Peter Richardson. Pls
> > forgive
> > me for not following up all your help and assitence on account of my
> > ignorance of the delay in uploading by google.
> >
> > By the time I was intimated, the thread has gone cold. Consequently I
> > read
> > up lot on regexes and sort of got a hang of what the code is about.
> >
> > Some sugested with inStrRev and split for which I get compile error as my
> > company provided only excel97.
> >
> >
> > I AM USING EXCEL97.
> >
> > FIRST CODE:
> >
> > This below code did shift the initials to the end of the name but ran once
> > and does not work again.
> >
> > Public Sub ConvertNames()
> > 'THIS WORKED FOR ONCE AND SECOND TIME NOT WORKING WHAT COULD BE REASON
> > Dim RegEx As Object
> > Dim Cell As Range
> > Set RegEx = CreateObject("vbscript.regexp")
> > RegEx.Global = True
> > RegEx.MultiLine = True
> > RegEx.IgnoreCase = True
> > RegEx.Pattern = "^([a-z..]*\.)([a-z]+)$"
> >
> > For Each Cell In Selection
> > Cell = RegEx.Replace(Cell, "$2 $1")
> > Next Cell
> >
> > End Sub
> >
> >
> > SECOND CODE:
> >
> > This below code works fine but the initials goes in the middle if I have
> > two
> > names.
> >
> > Option Explicit
> > Sub MoveInit()
> >
> > 'given by ron rosenfield
> > Dim c As Range
> > Dim oRegex As Object
> > Dim oMatchCollection As Object
> > Dim i As Long
> > Const sPattern As String = "(([A-Z]\.\s?)*)(\w+)"
> >
> > Set oRegex = CreateObject("VBScript.Regexp")
> > oRegex.Global = True
> > oRegex.ignorecase = True
> > oRegex.Pattern = sPattern
> >
> > For Each c In Selection
> > c.Offset(0, 1).ClearContents
> > c.Offset(0, 1).Value = oRegex.Replace(c.Text, "$3 $1")
> > Next c
> > End Sub
> >
> > So pls help me in
> > A) What must have gone wrong in First code.
> > B) What must be the code to put the initials at the end if the cell has
> > two
> > names like
> > A.S.D.PETER GREG.
> >
> > Needless to say that I will be watching for all the post continuously all
> > day long unlike my earlier posts on this same subject.
> >
> > brgds/captgnvr

>
>

 
Reply With Quote
 
Ron Rosenfeld
Guest
Posts: n/a
 
      22nd Jul 2007
On Sat, 21 Jul 2007 23:42:00 -0700, CAPTGNVR
<(E-Mail Removed)> wrote:

>DEAR ALL,
>
>I copied about 10 names from the thousands i have and ran the below code
>(not my brains but got assistance thanks to Mr. Ron Rosenfield, Gary
>student, Jim Thomlinson, Kevin Jones, Mike and Peter Richardson. Pls forgive
>me for not following up all your help and assitence on account of my
>ignorance of the delay in uploading by google.
>
> By the time I was intimated, the thread has gone cold. Consequently I read
>up lot on regexes and sort of got a hang of what the code is about.
>
>Some sugested with inStrRev and split for which I get compile error as my
>company provided only excel97.
>
>
>I AM USING EXCEL97.
>
>FIRST CODE:
>
>This below code did shift the initials to the end of the name but ran once
>and does not work again.
>
>Public Sub ConvertNames()
>'THIS WORKED FOR ONCE AND SECOND TIME NOT WORKING WHAT COULD BE REASON
>Dim RegEx As Object
>Dim Cell As Range
>Set RegEx = CreateObject("vbscript.regexp")
>RegEx.Global = True
>RegEx.MultiLine = True
>RegEx.IgnoreCase = True
>RegEx.Pattern = "^([a-z..]*\.)([a-z]+)$"
>
>For Each Cell In Selection
>Cell = RegEx.Replace(Cell, "$2 $1")
>Next Cell
>
>End Sub
>
>
>SECOND CODE:
>
>This below code works fine but the initials goes in the middle if I have two
>names.
>
>Option Explicit
>Sub MoveInit()
>
>'given by ron rosenfield
>Dim c As Range
>Dim oRegex As Object
>Dim oMatchCollection As Object
>Dim i As Long
>Const sPattern As String = "(([A-Z]\.\s?)*)(\w+)"
>
>Set oRegex = CreateObject("VBScript.Regexp")
>oRegex.Global = True
>oRegex.ignorecase = True
>oRegex.Pattern = sPattern
>
>For Each c In Selection
>c.Offset(0, 1).ClearContents
>c.Offset(0, 1).Value = oRegex.Replace(c.Text, "$3 $1")
>Next c
>End Sub
>
>So pls help me in
>A) What must have gone wrong in First code.
>B) What must be the code to put the initials at the end if the cell has two
>names like
> A.S.D.PETER GREG.
>
>Needless to say that I will be watching for all the post continuously all
>day long unlike my earlier posts on this same subject.
>
>brgds/captgnvr



Had you read my first response completely, you would have seen that I asked you
that very question of what you wanted for output if there were multiple names.


Try this for your multiple names issue:

========================================
Option Explicit
Sub MoveInit()
Dim c As Range
Dim oRegex As Object
Const sPattern As String = "(([A-Z]\.\s?)*)(.*)"

Set oRegex = CreateObject("VBScript.Regexp")
oRegex.Global = True
oRegex.ignorecase = False
oRegex.Pattern = sPattern

For Each c In Selection
c.Offset(0, 1).ClearContents
c.Offset(0, 1).Value = oRegex.Replace(c.Text, "$3 $1")
Next c
End Sub
============================================
--ron
 
Reply With Quote
 
=?Utf-8?B?Q0FQVEdOVlI=?=
Guest
Posts: n/a
 
      22nd Jul 2007
DRon
Yessssssss. It works perfect and thanks for ur guidance. I hv replied to
the original post answering if the cell has two names. Further I hv also
sent one email also requesting for little bit of explanations. Subsequently
I managed to find on google about regexp and figured out a bit.

This is will be complete if you could pls clarify how u arrived "$3 $1" in
the code
"""oRegex.Replace(c.Text, "$3 $1")""""

wrgds/captgnvr

"Ron Rosenfeld" wrote:

> On Sat, 21 Jul 2007 23:42:00 -0700, CAPTGNVR
> <(E-Mail Removed)> wrote:
>
> >DEAR ALL,
> >
> >I copied about 10 names from the thousands i have and ran the below code
> >(not my brains but got assistance thanks to Mr. Ron Rosenfield, Gary
> >student, Jim Thomlinson, Kevin Jones, Mike and Peter Richardson. Pls forgive
> >me for not following up all your help and assitence on account of my
> >ignorance of the delay in uploading by google.
> >
> > By the time I was intimated, the thread has gone cold. Consequently I read
> >up lot on regexes and sort of got a hang of what the code is about.
> >
> >Some sugested with inStrRev and split for which I get compile error as my
> >company provided only excel97.
> >
> >
> >I AM USING EXCEL97.
> >
> >FIRST CODE:
> >
> >This below code did shift the initials to the end of the name but ran once
> >and does not work again.
> >
> >Public Sub ConvertNames()
> >'THIS WORKED FOR ONCE AND SECOND TIME NOT WORKING WHAT COULD BE REASON
> >Dim RegEx As Object
> >Dim Cell As Range
> >Set RegEx = CreateObject("vbscript.regexp")
> >RegEx.Global = True
> >RegEx.MultiLine = True
> >RegEx.IgnoreCase = True
> >RegEx.Pattern = "^([a-z..]*\.)([a-z]+)$"
> >
> >For Each Cell In Selection
> >Cell = RegEx.Replace(Cell, "$2 $1")
> >Next Cell
> >
> >End Sub
> >
> >
> >SECOND CODE:
> >
> >This below code works fine but the initials goes in the middle if I have two
> >names.
> >
> >Option Explicit
> >Sub MoveInit()
> >
> >'given by ron rosenfield
> >Dim c As Range
> >Dim oRegex As Object
> >Dim oMatchCollection As Object
> >Dim i As Long
> >Const sPattern As String = "(([A-Z]\.\s?)*)(\w+)"
> >
> >Set oRegex = CreateObject("VBScript.Regexp")
> >oRegex.Global = True
> >oRegex.ignorecase = True
> >oRegex.Pattern = sPattern
> >
> >For Each c In Selection
> >c.Offset(0, 1).ClearContents
> >c.Offset(0, 1).Value = oRegex.Replace(c.Text, "$3 $1")
> >Next c
> >End Sub
> >
> >So pls help me in
> >A) What must have gone wrong in First code.
> >B) What must be the code to put the initials at the end if the cell has two
> >names like
> > A.S.D.PETER GREG.
> >
> >Needless to say that I will be watching for all the post continuously all
> >day long unlike my earlier posts on this same subject.
> >
> >brgds/captgnvr

>
>
> Had you read my first response completely, you would have seen that I asked you
> that very question of what you wanted for output if there were multiple names.
>
>
> Try this for your multiple names issue:
>
> ========================================
> Option Explicit
> Sub MoveInit()
> Dim c As Range
> Dim oRegex As Object
> Const sPattern As String = "(([A-Z]\.\s?)*)(.*)"
>
> Set oRegex = CreateObject("VBScript.Regexp")
> oRegex.Global = True
> oRegex.ignorecase = False
> oRegex.Pattern = sPattern
>
> For Each c In Selection
> c.Offset(0, 1).ClearContents
> c.Offset(0, 1).Value = oRegex.Replace(c.Text, "$3 $1")
> Next c
> End Sub
> ============================================
> --ron
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: java script regular expression password validation Cowboy \(Gregory A. Beamer\) Microsoft ASP .NET 0 12th Feb 2009 09:12 PM
Help with regular expresion LEM Microsoft C# .NET 6 3rd Apr 2007 09:21 PM
VB Script Regular Expressions - Missing John Taylor Microsoft Excel Misc 2 17th Aug 2006 12:32 PM
Regular expresion =?Utf-8?B?U2hhZG93T2ZUaGVCZWFzdA==?= Microsoft C# .NET 0 20th Mar 2005 04:25 PM
Ask help for regular expresion =?Utf-8?B?REQ=?= Microsoft Dot NET Framework 0 29th Mar 2004 11:16 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:03 AM.