View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Claus Busch Claus Busch is offline
external usenet poster
 
Posts: 3,872
Default Name break into half and reverse to upper case

Hi,

Am Mon, 29 Oct 2012 10:47:47 +0000 schrieb shrinivasmj:

EG NAME INOUT AND OUTPUT

Srinivas SRINIVAS
srinivas m M,SRINIVAS

srinivas m.j. J,SRINIVAS M.

srinivas m.j.h. J.H,SRINIVAS M.

srinivas m. j. h. k. H. K,SRINIVAS M. J.

srinivas m. j. h. k. l. H. K. L,SRINIVAS M. J.


try it with VBA (modify to suit):

Sub RevStr()
Dim c As Range
Dim LRow As Long
Dim mySearch As Integer
Dim Start As Integer

LRow = Cells(Rows.Count, 1).End(xlUp).Row
For Each c In Range("A1:A" & LRow)
If InStr(c, ".") = 0 And InStr(Trim(c), " ") 0 Then
mySearch = 2
Else
mySearch = Len(c) - Len(Replace(c, ".", "")) + 1
End If

Select Case mySearch
Case 2
Start = WorksheetFunction.Find(" ", c) + 1
c = Mid(c, Start, 99) & ", " & Left(c, Start - 2)
Case 3, 4
c = WorksheetFunction.Substitute(c, ".", "#", 1)
Start = WorksheetFunction.Find("#", c) + 1
c = Mid(c, Start, 99) & ", " & Left(c, Start - 2) & "."
Case 5, 6, 7, 8, 9, 10
c = WorksheetFunction.Substitute(c, ".", "#", 2)
Start = WorksheetFunction.Find("#", c) + 1
c = Mid(c, Start, 99) & ", " & Left(c, Start - 2) & "."
End Select

c = UCase(Trim(c))

Next
End Sub


Regards
Claus Busch
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2