Is it possible?

H

Help on formula

I have two columns of names A and B (A=First name B=Last name). My question
is, without changing the column A and B, how could be the Macro defined so
that column A’s or B’s characters are if less than four, the comas (,)
inserts into to make it four i.e. “Leo=LEO,†“A=A,,,â€. Blank fields should
stay blank and if it’s possible if the small letters of name in column A or B
can also be capitalized in the same Macro. To explore the possibilities I
thanks in advance…

Sincerely Shan
 
G

Graham Mayor

I take it that you want to change the entries in the table to add commas as
appropriate and format as upper case? Then assuming the first table in the
document and the first two columns of that table, the following will do
that.

Sub AddCommas()
Dim oTable As Table
Dim oRng As Range
Dim i As Long, j As Long, k As Long
Set oTable = ActiveDocument.Tables(1)
For i = 1 To oTable.Rows.Count
For j = 1 To 2
Set oRng = oTable.Cell(i, j).Range
oRng.End = oRng.End - 1
If Len(oRng) < 4 Then
For k = 1 To 4 - Len(oRng)
oRng.InsertAfter ","
Next k
End If
Next j
Next i
End Sub

http://www.gmayor.com/installing_macro.htm

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top