View Single Post
  #8   Report Post  
Greg
 
Posts: n/a
Default

Max,

Thanks. When I saw it, I figured immediately that it was an index
value. I just couldn't figure out how you came upon using it. I have
been using this new gained knowlegde to play around with some code for
rearranging a list of names:

Sub Test()
Dim oPara As Word.Paragraph
Dim oRng As Word.Range
Dim pRef0 As String
Dim pRef1 As String
Dim pRef2 As String
Dim pRef3 As String
Dim pRef4 As String
Dim i As Long

For Each oPara In ActiveDocument.Paragraphs
Set oRng = oPara.Range
oRng.MoveEnd wdCharacter, -1
i = UBound(Split(oRng)) + 1
Select Case i
Case Is 1
pRef1 = Split(oRng)(0)
pRef2 = Split(oRng)(1)
Select Case i
Case Is 3
oRng.Text = pRef2 & ", " & pRef1
Case Is 4
pRef3 = Split(oRng)(2)
If InStr("SR.Sr.JR.Jr.IIIVIII", pRef3) 0 Then
oRng.Text = pRef2 & ", " & pRef1 & ", " & pRef3
Else
oRng.Text = pRef3 & ", " & pRef1 & " " & pRef2
End If
Case Is = 4
pRef3 = Split(oRng)(2)
pRef4 = Split(oRng)(3)
If InStr("SR.Sr.JR.Jr.IIIVIII", pRef4) 0 Then
oRng.Text = pRef3 & ", " & pRef1 & " " & pRef2 _
& ", " & pRef4
Else
oRng.Text = pRef4 & ", " & pRef1 & " " & pRef2 _
& " " & pRef3
End If
Case Else
MsgBox oRng & " contains too many elements" _
& " for this procedure to rearrange."
End Select
Case Else
End Select
Next
End Sub

I should change the variable names, but it seems to work pretty good
for rearranging names into from First Name, MI, Last Name, Suffix to
Last Name, First Name MI, Suffix