ExcelTip.com
Account Icon Account Icon Account Icon
ExcelTip.com

Go Back   Excel Help Forum > Limelight Media - ExcelTip.com Books > F1 Get the most out of Excel Formulas & Functions

Notices

Reply
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1  
Old 08-16-2006, 06:43 AM
sujit_shukla sujit_shukla is offline
Registered User
 
Join Date: 16 Aug 2006
Posts: 2
sujit_shukla is on a distinguished road
Exclamation Mid Function

Hi, I want to know more about Mid function

Suppose there is a praticular name "David Jonathan Anthony" So I want only the two initials of first name and complete last name to be extracted. So it should read as "D A Anthony" and names could always change, Cud be "Sujit Shukla", "Sunil Satyadhar Shukla". Any suggestion.
Reply With Quote
  #2  
Old 09-19-2006, 04:41 PM
oldchippy's Avatar
oldchippy oldchippy is offline
"Eagle Eyed" Forum Moderator
 
Join Date: 14 Feb 2005
Location: Worcester, UK
Posts: 5,934
oldchippy will become famous soon enough oldchippy will become famous soon enough
Thumbs up

Quote:
Originally Posted by sujit_shukla
Hi, I want to know more about Mid function

Suppose there is a praticular name "David Jonathan Anthony" So I want only the two initials of first name and complete last name to be extracted. So it should read as "D A Anthony" and names could always change, Cud be "Sujit Shukla", "Sunil Satyadhar Shukla". Any suggestion.
Hi sujit_shukla,

The following formula doesn't use the MID function, but suprisingly it does do what you want. It the longest formula I've ever created - is it a record?

Put your data in A8, then this in B8

=IF(IF(IF(ISERROR(SEARCH(" ",RIGHT(A8,LEN(A8)-SEARCH(" ",A8,1)),1)),0,SEARCH(" ",RIGHT(A8,LEN(A8)-SEARCH(" ",A8,1)),1))=0,"",LEFT(RIGHT(A8,LEN(A8)-SEARCH(" ",A8,1)),1))="",LEFT(A8,1)&" "&RIGHT(RIGHT(A8,LEN(A8)-SEARCH(" ",A8,1)),LEN(A8)-SEARCH(" ",A8,1)-IF(ISERROR(SEARCH(" ",RIGHT(A8,LEN(A8)-SEARCH(" ",A8,1)),1)),0,SEARCH(" ",RIGHT(A8,LEN(A8)-SEARCH(" ",A8,1)),1))),LEFT(A8,1)&" "&IF(IF(ISERROR(SEARCH(" ",RIGHT(A8,LEN(A8)-SEARCH(" ",A8,1)),1)),0,SEARCH(" ",RIGHT(A8,LEN(A8)-SEARCH(" ",A8,1)),1))=0,"",LEFT(RIGHT(A8,LEN(A8)-SEARCH(" ",A8,1)),1))&" "&RIGHT(RIGHT(A8,LEN(A8)-SEARCH(" ",A8,1)),LEN(A8)-SEARCH(" ",A8,1)-IF(ISERROR(SEARCH(" ",RIGHT(A8,LEN(A8)-SEARCH(" ",A8,1)),1)),0,SEARCH(" ",RIGHT(A8,LEN(A8)-SEARCH(" ",A8,1)),1))))

Copy and paste, don't try to type it!

There must be a way to shorten it, if anybody can let me know please
oldchippy
Reply With Quote
  #3  
Old 09-19-2006, 05:03 PM
VBA Noob's Avatar
VBA Noob VBA Noob is online now
Wicked Forum Moderator
 
Join Date: 25 Apr 2006
Location: London, England
Posts: 11,003
VBA Noob will become famous soon enough VBA Noob will become famous soon enough
Hi,

Would this not work

=UPPER(LEFT(A8,2))&" "&RIGHT(TRIM(A8),LEN(TRIM(A8))
-IF(ISERROR(FIND(" ",TRIM(A8),FIND(" ",TRIM(A8),1)+1)),FIND(" ",TRIM(A8),1),FIND(" ",TRIM(A8),FIND(" ",TRIM(A8),1)+1)))

VBA Noob
Reply With Quote
  #4  
Old 09-19-2006, 05:19 PM
oldchippy's Avatar
oldchippy oldchippy is offline
"Eagle Eyed" Forum Moderator
 
Join Date: 14 Feb 2005
Location: Worcester, UK
Posts: 5,934
oldchippy will become famous soon enough oldchippy will become famous soon enough
Thumbs up

Quote:
Originally Posted by VBA Noob
Hi,

Would this not work

=UPPER(LEFT(A8,2))&" "&RIGHT(TRIM(A8),LEN(TRIM(A8))
-IF(ISERROR(FIND(" ",TRIM(A8),FIND(" ",TRIM(A8),1)+1)),FIND(" ",TRIM(A8),1),FIND(" ",TRIM(A8),FIND(" ",TRIM(A8),1)+1)))

VBA Noob
Hello VBA Noob,

No I can't get it to work, it gives the first and second letter of the first name and the surname, try on

Hello VBA Noob and you get "HE Noob"

oldchippy
Reply With Quote
  #5  
Old 09-19-2006, 05:24 PM
VBA Noob's Avatar
VBA Noob VBA Noob is online now
Wicked Forum Moderator
 
Join Date: 25 Apr 2006
Location: London, England
Posts: 11,003
VBA Noob will become famous soon enough VBA Noob will become famous soon enough
Hi oldchippy,

Is that what he wanted ??

Code:
Suppose there is a praticular name "David Jonathan Anthony" So I want only the two initials of first name and complete last name to be extracted
VBA Noob
Reply With Quote
  #6  
Old 09-19-2006, 05:30 PM
oldchippy's Avatar
oldchippy oldchippy is offline
"Eagle Eyed" Forum Moderator
 
Join Date: 14 Feb 2005
Location: Worcester, UK
Posts: 5,934
oldchippy will become famous soon enough oldchippy will become famous soon enough
Thumbs up

You’re absolutely right, I can’t see for looking. Oh well if you ever need to extract the first letter of the first and second names + last name at least you'll know where to find it.

Thanks for pointing it out

oldchippy
Reply With Quote
  #7  
Old 09-19-2006, 06:09 PM
VBA Noob's Avatar
VBA Noob VBA Noob is online now
Wicked Forum Moderator
 
Join Date: 25 Apr 2006
Location: London, England
Posts: 11,003
VBA Noob will become famous soon enough VBA Noob will become famous soon enough
Hi,

This is shorter by 288 characters

=IF(LEN(SUBSTITUTE(TRIM(A8),CHAR(32),CHAR(32)&CHAR(32)))-LEN(TRIM(A8))+1>2,
LEFT(A8,1)&" "&UPPER(MID(A8,FIND(" ",A8,1)+1,1))&" "&RIGHT(TRIM(A8),LEN(TRIM(A8))
-IF(ISERROR(FIND(" ",TRIM(A8),FIND(" ",TRIM(A8),1)+1)),FIND(" ",TRIM(A8),1),FIND(" ",TRIM(A8),FIND(" ",TRIM(A8),1)+1))),LEFT(A8,1)
&" "&RIGHT(TRIM(A8),LEN(TRIM(A8))
-IF(ISERROR(FIND(" ",TRIM(A8),FIND(" ",TRIM(A8),1)+1)),FIND(" ",TRIM(A8),1),FIND(" ",TRIM(A8),FIND(" ",TRIM(A8),1)+1))))

VBA Noob
Reply With Quote
  #8  
Old 09-19-2006, 06:17 PM
oldchippy's Avatar
oldchippy oldchippy is offline
"Eagle Eyed" Forum Moderator
 
Join Date: 14 Feb 2005
Location: Worcester, UK
Posts: 5,934
oldchippy will become famous soon enough oldchippy will become famous soon enough
No sorry, still throw up an error, now coming up with

H V BA Noob

I think it needs those additional 288 characters

oldchippy
Reply With Quote
  #9  
Old 09-19-2006, 06:34 PM
VBA Noob's Avatar
VBA Noob VBA Noob is online now
Wicked Forum Moderator
 
Join Date: 25 Apr 2006
Location: London, England
Posts: 11,003
VBA Noob will become famous soon enough VBA Noob will become famous soon enough
What text are you using to get H V BA Noob

VBA Noob
Reply With Quote
  #10  
Old 09-19-2006, 06:38 PM
oldchippy's Avatar
oldchippy oldchippy is offline
"Eagle Eyed" Forum Moderator
 
Join Date: 14 Feb 2005
Location: Worcester, UK
Posts: 5,934
oldchippy will become famous soon enough oldchippy will become famous soon enough
"Hello VBA Noob"
Reply With Quote
  #11  
Old 09-19-2006, 06:42 PM
VBA Noob's Avatar
VBA Noob VBA Noob is online now
Wicked Forum Moderator
 
Join Date: 25 Apr 2006
Location: London, England
Posts: 11,003
VBA Noob will become famous soon enough VBA Noob will become famous soon enough
Interesting

My formula returns H V Noob the same as yours not H V BA Noob

VBA Noob
Reply With Quote
  #12  
Old 09-19-2006, 06:44 PM
oldchippy's Avatar
oldchippy oldchippy is offline
"Eagle Eyed" Forum Moderator
 
Join Date: 14 Feb 2005
Location: Worcester, UK
Posts: 5,934
oldchippy will become famous soon enough oldchippy will become famous soon enough
????? How many characters does your formula have, I get it to 438?
Reply With Quote
  #13  
Old 09-19-2006, 06:50 PM
VBA Noob's Avatar
VBA Noob VBA Noob is online now
Wicked Forum Moderator
 
Join Date: 25 Apr 2006
Location: London, England
Posts: 11,003
VBA Noob will become famous soon enough VBA Noob will become famous soon enough
I got 443 but that was with the ' at the start.

Try this without indents

=IF(LEN(SUBSTITUTE(TRIM(A8),CHAR(32),CHAR(32)&CHAR(32)))-LEN(TRIM(A8))+1>2,LEFT(A8,1)&" "&UPPER(MID(A8,FIND(" ",A8,1)+1,1))&" "&RIGHT(TRIM(A8),LEN(TRIM(A8))-IF(ISERROR(FIND(" ",TRIM(A8),FIND(" ",TRIM(A8),1)+1)),FIND(" ",TRIM(A8),1),FIND(" ",TRIM(A8),FIND(" ",TRIM(A8),1)+1))),LEFT(A8,1)&" "&RIGHT(TRIM(A8),LEN(TRIM(A8))-IF(ISERROR(FIND(" ",TRIM(A8),FIND(" ",TRIM(A8),1)+1)),FIND(" ",TRIM(A8),1),FIND(" ",TRIM(A8),FIND(" ",TRIM(A8),1)+1))))

VBA Noob
Reply With Quote
  #14  
Old 09-19-2006, 06:54 PM
oldchippy's Avatar
oldchippy oldchippy is offline
"Eagle Eyed" Forum Moderator
 
Join Date: 14 Feb 2005
Location: Worcester, UK
Posts: 5,934
oldchippy will become famous soon enough oldchippy will become famous soon enough
Hooray, well done. How come, where did the indents come from?
Reply With Quote
  #15  
Old 09-19-2006, 06:57 PM
oldchippy's Avatar
oldchippy oldchippy is offline
"Eagle Eyed" Forum Moderator
 
Join Date: 14 Feb 2005
Location: Worcester, UK
Posts: 5,934
oldchippy will become famous soon enough oldchippy will become famous soon enough
I still only get LEN to equal 439 including ' but it doesn't count that character
Reply With Quote
Reply

Bookmarks

New topics in F1 Get the most out of Excel Formulas & Functions


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


All times are GMT -4. The time now is 06:05 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0