LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 87
Default WHAT COULD BE THE REASON FOR VB SCRIPT REGULAR EXPRESION TO WORK O

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
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Script doesn't work when cells are merged. [email protected] Excel Discussion (Misc queries) 2 January 26th 07 07:36 AM
VB Script Regular Expressions - Missing John Taylor Excel Discussion (Misc queries) 2 August 17th 06 12:32 PM
Is there a script that will work? RayB[_2_] Excel Programming 1 July 18th 06 04:21 PM
Why won't this simple VDB script work on Excel 2002. Calle Excel Programming 4 May 29th 06 02:56 PM
Why won't this simple VBA script work in excel 2002? Calle Excel Discussion (Misc queries) 1 May 29th 06 12:21 PM


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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"