Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 271
Default Need Period After Initials

I imported a database into an Excel spreadsheet. The middle initials in the
names don't have periods after them. Is there a wildcard character that I
can use to replace initials without periods to initials with periods?
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 11,058
Default Need Period After Initials

Try this small UDF:

Function initalizer(r As Range) As String
v = r.Value
s = Split(v, " ")
If UBound(s) < 2 Then
initalizer = v
Exit Function
End If
If Len(s(1)) 1 Then
initalizer = v
Exit Function
End If
initalizer = s(0) & " " & s(1) & ". " & s(2)
End Function
--
Gary''s Student - gsnu200721
  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 3,718
Default Need Period After Initials

Assuming your data look like this in A1: John Z Doe

B1: =SUBSTITUTE(A1," ",". ",LEN(A1)-LEN(SUBSTITUTE(A1," ","")))


"Susan" wrote:

I imported a database into an Excel spreadsheet. The middle initials in the
names don't have periods after them. Is there a wildcard character that I
can use to replace initials without periods to initials with periods?

  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1,117
Default Need Period After Initials

hey!
:)
susan

On May 14, 12:43 pm, Susan wrote:
I imported a database into an Excel spreadsheet. The middle initials in the
names don't have periods after them. Is there a wildcard character that I
can use to replace initials without periods to initials with periods?



  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 5,441
Default Need Period After Initials

Susan,

If your name strings could have 2 or more initials rather than just one:

Susan A B Smith

then this UDF will work, used like:

=MidInit(A1)

Function MidInit(myName As String) As String
Dim i As Integer
Dim myStr As String

myStr = myName
For i = 1 To Len(myName) - 2
If Mid(myName, i, 1) = " " And Mid(myName, i + 2, 1) = " " Then
myStr = Left(myName, i + 1) & "." & Mid(myName, i + 2, Len(myName))
myStr = MidInit(myStr)
End If
Next i

MidInit = myStr
End Function

HTH,
Bernie
MS Excel MVP


"Susan" wrote in message
...
I imported a database into an Excel spreadsheet. The middle initials in the
names don't have periods after them. Is there a wildcard character that I
can use to replace initials without periods to initials with periods?





  #6   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 271
Default Need Period After Initials

Where do I enter that?

"Gary''s Student" wrote:

Try this small UDF:

Function initalizer(r As Range) As String
v = r.Value
s = Split(v, " ")
If UBound(s) < 2 Then
initalizer = v
Exit Function
End If
If Len(s(1)) 1 Then
initalizer = v
Exit Function
End If
initalizer = s(0) & " " & s(1) & ". " & s(2)
End Function
--
Gary''s Student - gsnu200721

  #7   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 3,440
Default Need Period After Initials

Hi Susan,

================================================
Pasting a User Defined Function (UDF)
Niek Otten, March 31, 2006

If you find a VBA function on the Internet or somebody mails you one, and you don't know how to implement it, follow these
steps:

Select all the text of the function.
CTRL+C (that is, press and hold down the CTRL key, press C, release both). This a shortcut for Copy.
Go to Excel. Press ALT+F11 (same method: press and hold the ALT key, press the F11 key and release both). You are now in the
Visual Basic Editor (VBE).
From the menu bar, choose InsertModule. There should now be a blank module sheet in front of you. Click in it and then
press CTRL+V (same method.). This a shortcut for Paste. You should now see the text of the function in the Module.
Press ALT+F11 again to return to your Excel worksheet.
You should now be able to use the function as if it were a built-in function of Excel, like =SUM(..)
================================================



--
Kind regards,

Niek Otten
Microsoft MVP - Excel

"Susan" wrote in message ...
| Where do I enter that?
|
| "Gary''s Student" wrote:
|
| Try this small UDF:
|
| Function initalizer(r As Range) As String
| v = r.Value
| s = Split(v, " ")
| If UBound(s) < 2 Then
| initalizer = v
| Exit Function
| End If
| If Len(s(1)) 1 Then
| initalizer = v
| Exit Function
| End If
| initalizer = s(0) & " " & s(1) & ". " & s(2)
| End Function
| --
| Gary''s Student - gsnu200721


  #8   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 11,058
Default Need Period After Initials


UDFs are very easy to install and use:

1. ALT-F11 brings up the VBE window
2. ALT-I
ALT-M opens a fresh module
3. paste the stuff in and close the VBE window

If you save the workbook, the UDF will be saved with it.


To remove the UDF:

1. bring up the VBE window as above
2. clear the code out
3. close the VBE window

To learn more about UDFs in general, see:

http://www.mvps.org/dmcritchie/excel/getstarted.htm


to use:
If A1 thru A5 contain:

Cher
Victor Laszo
William Randolph Hearst
William R Hearst

In B1 put:

=initalizer(A1)
and copy down

to see:

Cher
Victor Laszo
William Randolph Hearst
William R. Hearst


If the name is one or two words, no change is made.
Only if the middle name is one character long is the period added
--
Gary''s Student - gsnu200721
  #9   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 271
Default Need Period After Initials

I pasted the UDF into a module in VBE, but it hasn't done anything to the
worksheet. Is there some way I have to run it?

"Gary''s Student" wrote:


UDFs are very easy to install and use:

1. ALT-F11 brings up the VBE window
2. ALT-I
ALT-M opens a fresh module
3. paste the stuff in and close the VBE window

If you save the workbook, the UDF will be saved with it.


To remove the UDF:

1. bring up the VBE window as above
2. clear the code out
3. close the VBE window

To learn more about UDFs in general, see:

http://www.mvps.org/dmcritchie/excel/getstarted.htm


to use:
If A1 thru A5 contain:

Cher
Victor Laszo
William Randolph Hearst
William R Hearst

In B1 put:

=initalizer(A1)
and copy down

to see:

Cher
Victor Laszo
William Randolph Hearst
William R. Hearst


If the name is one or two words, no change is made.
Only if the middle name is one character long is the period added
--
Gary''s Student - gsnu200721

  #10   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 3,268
Default Need Period After Initials

You should read the post or check out the link that was provided? You use it
as a regular function, to quote the post you replied to.

"to use:
If A1 thru A5 contain:

Cher
Victor Laszo
William Randolph Hearst
William R Hearst

In B1 put:

=initalizer(A1)
and copy down

to see:

Cher
Victor Laszo
William Randolph Hearst
William R. Hearst"



--
Regards,

Peo Sjoblom


"Susan" wrote in message
...
I pasted the UDF into a module in VBE, but it hasn't done anything to the
worksheet. Is there some way I have to run it?

"Gary''s Student" wrote:


UDFs are very easy to install and use:

1. ALT-F11 brings up the VBE window
2. ALT-I
ALT-M opens a fresh module
3. paste the stuff in and close the VBE window

If you save the workbook, the UDF will be saved with it.


To remove the UDF:

1. bring up the VBE window as above
2. clear the code out
3. close the VBE window

To learn more about UDFs in general, see:

http://www.mvps.org/dmcritchie/excel/getstarted.htm


to use:
If A1 thru A5 contain:

Cher
Victor Laszo
William Randolph Hearst
William R Hearst

In B1 put:

=initalizer(A1)
and copy down

to see:

Cher
Victor Laszo
William Randolph Hearst
William R. Hearst


If the name is one or two words, no change is made.
Only if the middle name is one character long is the period added
--
Gary''s Student - gsnu200721





  #11   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 271
Default Need Period After Initials

I have done all that but still don't see any change to my spreadsheet. What
do I have to do to make the function work? Does it have to be run?

"Niek Otten" wrote:

Hi Susan,

================================================
Pasting a User Defined Function (UDF)
Niek Otten, March 31, 2006

If you find a VBA function on the Internet or somebody mails you one, and you don't know how to implement it, follow these
steps:

Select all the text of the function.
CTRL+C (that is, press and hold down the CTRL key, press C, release both). This a shortcut for Copy.
Go to Excel. Press ALT+F11 (same method: press and hold the ALT key, press the F11 key and release both). You are now in the
Visual Basic Editor (VBE).
From the menu bar, choose InsertModule. There should now be a blank module sheet in front of you. Click in it and then
press CTRL+V (same method.). This a shortcut for Paste. You should now see the text of the function in the Module.
Press ALT+F11 again to return to your Excel worksheet.
You should now be able to use the function as if it were a built-in function of Excel, like =SUM(..)
================================================



--
Kind regards,

Niek Otten
Microsoft MVP - Excel

"Susan" wrote in message ...
| Where do I enter that?
|
| "Gary''s Student" wrote:
|
| Try this small UDF:
|
| Function initalizer(r As Range) As String
| v = r.Value
| s = Split(v, " ")
| If UBound(s) < 2 Then
| initalizer = v
| Exit Function
| End If
| If Len(s(1)) 1 Then
| initalizer = v
| Exit Function
| End If
| initalizer = s(0) & " " & s(1) & ". " & s(2)
| End Function
| --
| Gary''s Student - gsnu200721



  #12   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 271
Default Need Period After Initials

The function below does not work. I get #NAME? when I type it into the cells.

"Peo Sjoblom" wrote:

You should read the post or check out the link that was provided? You use it
as a regular function, to quote the post you replied to.

"to use:
If A1 thru A5 contain:

Cher
Victor Laszo
William Randolph Hearst
William R Hearst

In B1 put:

=initalizer(A1)
and copy down

to see:

Cher
Victor Laszo
William Randolph Hearst
William R. Hearst"



--
Regards,

Peo Sjoblom


"Susan" wrote in message
...
I pasted the UDF into a module in VBE, but it hasn't done anything to the
worksheet. Is there some way I have to run it?

"Gary''s Student" wrote:


UDFs are very easy to install and use:

1. ALT-F11 brings up the VBE window
2. ALT-I
ALT-M opens a fresh module
3. paste the stuff in and close the VBE window

If you save the workbook, the UDF will be saved with it.


To remove the UDF:

1. bring up the VBE window as above
2. clear the code out
3. close the VBE window

To learn more about UDFs in general, see:

http://www.mvps.org/dmcritchie/excel/getstarted.htm


to use:
If A1 thru A5 contain:

Cher
Victor Laszo
William Randolph Hearst
William R Hearst

In B1 put:

=initalizer(A1)
and copy down

to see:

Cher
Victor Laszo
William Randolph Hearst
William R. Hearst


If the name is one or two words, no change is made.
Only if the middle name is one character long is the period added
--
Gary''s Student - gsnu200721




  #13   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 3,268
Default Need Period After Initials

If you get a name error then you either didn't copy the code into a regular
module or spelled it incorrectly.
Make sure you didn't paste it into a worksheet module, if it is done
correctly you won't get any name errors. Press Alt + F11, select the
workbook in the project pane to the left, then click insert module, then
paste the code into the main window that opens. Press Alt + Q to close the
VBA editor and finally save the workbook


--
Regards,

Peo Sjoblom



"Susan" wrote in message
...
The function below does not work. I get #NAME? when I type it into the
cells.

"Peo Sjoblom" wrote:

You should read the post or check out the link that was provided? You use
it
as a regular function, to quote the post you replied to.

"to use:
If A1 thru A5 contain:

Cher
Victor Laszo
William Randolph Hearst
William R Hearst

In B1 put:

=initalizer(A1)
and copy down

to see:

Cher
Victor Laszo
William Randolph Hearst
William R. Hearst"



--
Regards,

Peo Sjoblom


"Susan" wrote in message
...
I pasted the UDF into a module in VBE, but it hasn't done anything to
the
worksheet. Is there some way I have to run it?

"Gary''s Student" wrote:


UDFs are very easy to install and use:

1. ALT-F11 brings up the VBE window
2. ALT-I
ALT-M opens a fresh module
3. paste the stuff in and close the VBE window

If you save the workbook, the UDF will be saved with it.


To remove the UDF:

1. bring up the VBE window as above
2. clear the code out
3. close the VBE window

To learn more about UDFs in general, see:

http://www.mvps.org/dmcritchie/excel/getstarted.htm


to use:
If A1 thru A5 contain:

Cher
Victor Laszo
William Randolph Hearst
William R Hearst

In B1 put:

=initalizer(A1)
and copy down

to see:

Cher
Victor Laszo
William Randolph Hearst
William R. Hearst


If the name is one or two words, no change is made.
Only if the middle name is one character long is the period added
--
Gary''s Student - gsnu200721






  #14   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 11,058
Default Need Period After Initials

You need to use it like any other formula. In cell B1 enter:

=initalizer(A1)

and make sure a name is in A1
--
Gary''s Student - gsnu200721


"Susan" wrote:

I pasted the UDF into a module in VBE, but it hasn't done anything to the
worksheet. Is there some way I have to run it?

"Gary''s Student" wrote:


UDFs are very easy to install and use:

1. ALT-F11 brings up the VBE window
2. ALT-I
ALT-M opens a fresh module
3. paste the stuff in and close the VBE window

If you save the workbook, the UDF will be saved with it.


To remove the UDF:

1. bring up the VBE window as above
2. clear the code out
3. close the VBE window

To learn more about UDFs in general, see:

http://www.mvps.org/dmcritchie/excel/getstarted.htm


to use:
If A1 thru A5 contain:

Cher
Victor Laszo
William Randolph Hearst
William R Hearst

In B1 put:

=initalizer(A1)
and copy down

to see:

Cher
Victor Laszo
William Randolph Hearst
William R. Hearst


If the name is one or two words, no change is made.
Only if the middle name is one character long is the period added
--
Gary''s Student - gsnu200721

  #15   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 5,651
Default Need Period After Initials

On Mon, 14 May 2007 09:43:01 -0700, Susan
wrote:

I imported a database into an Excel spreadsheet. The middle initials in the
names don't have periods after them. Is there a wildcard character that I
can use to replace initials without periods to initials with periods?


One way:

Download and install Longre's free morefunc.xll add-in from
http://xcell05.free.fr

Then use this formula:

=REGEX.SUBSTITUTE(A1,"([A-Z])\s","[1]. ")

Note the <space after the <. in the last argument of the formula.

In this algorithm, a "middle initial" is defined as a capital letter followed
by a space and preceded by something that is not a letter, number or
underscore. If your data differs from that, post back.

So multiple initials in a name will have a <. inserted.

A J Fitz A. J. Fitz
Mary R Scots Mary R. Scots
Eskimo A B Joe Eskimo A. B. Joe
John Doe John Doe

--ron


  #16   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 5,651
Default Need Period After Initials

On Mon, 14 May 2007 10:22:02 -0700, Teethless mama
wrote:

Assuming your data look like this in A1: John Z Doe

B1: =SUBSTITUTE(A1," ",". ",LEN(A1)-LEN(SUBSTITUTE(A1," ","")))


"Susan" wrote:

I imported a database into an Excel spreadsheet. The middle initials in the
names don't have periods after them. Is there a wildcard character that I
can use to replace initials without periods to initials with periods?


But if there is no middle initial in a particular name?
--ron
  #17   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 5,651
Default Need Period After Initials

On Mon, 14 May 2007 13:34:00 -0400, "Bernie Deitrick" <deitbe @ consumer dot
org wrote:

Susan,

If your name strings could have 2 or more initials rather than just one:

Susan A B Smith

then this UDF will work, used like:

=MidInit(A1)

Function MidInit(myName As String) As String
Dim i As Integer
Dim myStr As String

myStr = myName
For i = 1 To Len(myName) - 2
If Mid(myName, i, 1) = " " And Mid(myName, i + 2, 1) = " " Then
myStr = Left(myName, i + 1) & "." & Mid(myName, i + 2, Len(myName))
myStr = MidInit(myStr)
End If
Next i

MidInit = myStr
End Function

HTH,
Bernie
MS Excel MVP


Of course, if the "initial" is at the beginning:

F Scott Fitzgerald
--ron
  #18   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 5,651
Default Need Period After Initials

On Mon, 14 May 2007 10:16:04 -0700, Gary''s Student
wrote:

Try this small UDF:

Function initalizer(r As Range) As String
v = r.Value
s = Split(v, " ")
If UBound(s) < 2 Then
initalizer = v
Exit Function
End If
If Len(s(1)) 1 Then
initalizer = v
Exit Function
End If
initalizer = s(0) & " " & s(1) & ". " & s(2)
End Function



Has a problem if there is a leading initial:

F Scott Fitzgerald,

or if there are more than three "names" or initials with at least one initial.

Eskimo A B Joe
--ron
  #19   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 11,058
Default Need Period After Initials

BE VERY CAREFUL about the spelling of the function in the worksheet. I
mis-spelled it in the VBA and it must be also "mis-spelled" in the worksheet.

use

initalizer

and not

initializer
--
Gary''s Student - gsnu200721


"Susan" wrote:

I pasted the UDF into a module in VBE, but it hasn't done anything to the
worksheet. Is there some way I have to run it?

"Gary''s Student" wrote:


UDFs are very easy to install and use:

1. ALT-F11 brings up the VBE window
2. ALT-I
ALT-M opens a fresh module
3. paste the stuff in and close the VBE window

If you save the workbook, the UDF will be saved with it.


To remove the UDF:

1. bring up the VBE window as above
2. clear the code out
3. close the VBE window

To learn more about UDFs in general, see:

http://www.mvps.org/dmcritchie/excel/getstarted.htm


to use:
If A1 thru A5 contain:

Cher
Victor Laszo
William Randolph Hearst
William R Hearst

In B1 put:

=initalizer(A1)
and copy down

to see:

Cher
Victor Laszo
William Randolph Hearst
William R. Hearst


If the name is one or two words, no change is made.
Only if the middle name is one character long is the period added
--
Gary''s Student - gsnu200721

  #20   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 5,651
Default Need Period After Initials

On Mon, 14 May 2007 19:57:24 -0400, Ron Rosenfeld
wrote:

On Mon, 14 May 2007 09:43:01 -0700, Susan
wrote:

I imported a database into an Excel spreadsheet. The middle initials in the
names don't have periods after them. Is there a wildcard character that I
can use to replace initials without periods to initials with periods?


One way:

Download and install Longre's free morefunc.xll add-in from
http://xcell05.free.fr

Then use this formula:

=REGEX.SUBSTITUTE(A1,"([A-Z])\s","[1]. ")

Note the <space after the <. in the last argument of the formula.

In this algorithm, a "middle initial" is defined as a capital letter followed
by a space and preceded by something that is not a letter, number or
underscore. If your data differs from that, post back.

So multiple initials in a name will have a <. inserted.

A J Fitz A. J. Fitz
Mary R Scots Mary R. Scots
Eskimo A B Joe Eskimo A. B. Joe
John Doe John Doe

--ron



Typo. Should be:

=REGEX.SUBSTITUTE(A1,"\b([A-Z])\s","[1]. ")
--ron


  #21   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 271
Default Need Period After Initials

This worked. Thanks so much.

"Gary''s Student" wrote:

You need to use it like any other formula. In cell B1 enter:

=initalizer(A1)

and make sure a name is in A1
--
Gary''s Student - gsnu200721


"Susan" wrote:

I pasted the UDF into a module in VBE, but it hasn't done anything to the
worksheet. Is there some way I have to run it?

"Gary''s Student" wrote:


UDFs are very easy to install and use:

1. ALT-F11 brings up the VBE window
2. ALT-I
ALT-M opens a fresh module
3. paste the stuff in and close the VBE window

If you save the workbook, the UDF will be saved with it.


To remove the UDF:

1. bring up the VBE window as above
2. clear the code out
3. close the VBE window

To learn more about UDFs in general, see:

http://www.mvps.org/dmcritchie/excel/getstarted.htm


to use:
If A1 thru A5 contain:

Cher
Victor Laszo
William Randolph Hearst
William R Hearst

In B1 put:

=initalizer(A1)
and copy down

to see:

Cher
Victor Laszo
William Randolph Hearst
William R. Hearst


If the name is one or two words, no change is made.
Only if the middle name is one character long is the period added
--
Gary''s Student - gsnu200721

  #22   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 271
Default Need Period After Initials

When I put the formula in, any name that has a middle initial with Jr. after
it, drops the Jr.

"Susan" wrote:

This worked. Thanks so much.

"Gary''s Student" wrote:

You need to use it like any other formula. In cell B1 enter:

=initalizer(A1)

and make sure a name is in A1
--
Gary''s Student - gsnu200721


"Susan" wrote:

I pasted the UDF into a module in VBE, but it hasn't done anything to the
worksheet. Is there some way I have to run it?

"Gary''s Student" wrote:


UDFs are very easy to install and use:

1. ALT-F11 brings up the VBE window
2. ALT-I
ALT-M opens a fresh module
3. paste the stuff in and close the VBE window

If you save the workbook, the UDF will be saved with it.


To remove the UDF:

1. bring up the VBE window as above
2. clear the code out
3. close the VBE window

To learn more about UDFs in general, see:

http://www.mvps.org/dmcritchie/excel/getstarted.htm


to use:
If A1 thru A5 contain:

Cher
Victor Laszo
William Randolph Hearst
William R Hearst

In B1 put:

=initalizer(A1)
and copy down

to see:

Cher
Victor Laszo
William Randolph Hearst
William R. Hearst


If the name is one or two words, no change is made.
Only if the middle name is one character long is the period added
--
Gary''s Student - gsnu200721

Reply
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
Create initials from Full name Charlotte Howard Excel Discussion (Misc queries) 3 March 21st 07 03:51 PM
how do i convert names to initials in excel dave glynn Excel Discussion (Misc queries) 2 September 26th 05 04:06 PM
Period to Period percentage change? cs120 Excel Discussion (Misc queries) 1 September 18th 05 12:05 PM
How to pluck out initials of a 2 or 3 word name Craig Brody Excel Worksheet Functions 1 September 9th 05 03:59 PM
! removing initials and titles from name cell ! Rayiw Excel Discussion (Misc queries) 1 January 28th 05 08:47 PM


All times are GMT +1. The time now is 11:24 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"