|
|||||||||||||||||||||
|
#1
|
|||
|
|||
|
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. |
|
#2
|
||||
|
||||
|
Quote:
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
|
|
#3
|
||||
|
||||
|
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 |
|
#4
|
||||
|
||||
|
Quote:
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
|
|
#5
|
||||
|
||||
|
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 |
|
#6
|
||||
|
||||
|
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
|
|
#7
|
||||
|
||||
|
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 |
|
#8
|
||||
|
||||
|
No sorry, still throw up an error, now coming up with
H V BA Noob I think it needs those additional 288 characters oldchippy |
|
#9
|
||||
|
||||
|
What text are you using to get H V BA Noob
VBA Noob |
|
#10
|
||||
|
||||
|
"Hello VBA Noob"
|
|
#11
|
||||
|
||||
|
Interesting
My formula returns H V Noob the same as yours not H V BA Noob VBA Noob |
|
#12
|
||||
|
||||
|
????? How many characters does your formula have, I get it to 438?
|
|
#13
|
||||
|
||||
|
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 |
|
#14
|
||||
|
||||
|
Hooray, well done. How come, where did the indents come from?
|
|
#15
|
||||
|
||||
|
I still only get LEN to equal 439 including ' but it doesn't count that character
|
![]() |
| 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 |
| Display Modes | Rate This Thread |
|
|