2016-04-28 49 views
1

例如,如果我的字符串是如何在EXCEL中的字符串中查找第二個元音之後的字符?

快樂歌

輸出應該

頁。

如果是空白的,則顯示 「無」

+0

如果你提供的,你已經嘗試做一些例子這將是巨大的,即使其完全錯誤的,因爲它可以幫助人們回答這個問題,並提高你的理解。 – miltonb

+1

在這裏被問到http://stackoverflow.com/q/36978101/641067作爲一個完整的問題。 – brettdj

回答

0

這將找到第二個元音後面的字母:

=IF(A1<>"",MID(A1,FIND("}}}",SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(LOWER(A1),"a","}"),"e","}"),"i","}"),"o","}"),"u","}"),"y","}"),"}","}}}",2))+1,1),"") 

![enter image description here

0

VBA的答案(含評論)是;

Function AfterSecondVowel(InputRange As String) 

'Put all the ascii codes for vowels (upper and lower case) in an array 
asciicodesforvowels = Array(65, 97, 69, 101, 73, 105, 79, 111, 85, 117) 
Dim Counter As Integer 
Dim i As Integer 

Counter = 0 

'Loop through all the letters in the input string 
For i = 1 To Len(InputRange) 

'Check to see if trying to match the current letter (converted to an ascii code) you are on from the input range 
'is in the array of ascii codes - If it isn't this will throw an error 
If Not IsError(Application.Match(Asc(Mid(InputRange, i, 1)), asciicodesforvowels, False)) Then 

'Increment your counter by 1 
Counter = Counter + 1 

End If 

'Check to see if the counter has reached 2 yet - You can change the = 2 bit here to any number you want to return 
'the letter after the N'th vowel 
If Counter = 2 Then 
'If it has reached the second vowel, skip to the next letter 
i = i + 1 
'Set the output of the function to this letter you've moved to 
AfterSecondVowel = Mid(InputRange, i, 1) 
'Exit the function 
Exit Function 

End If 
'Otherwise loop through to the next letter 
Next i 

'If you reach the end of the letters without exiting the function it's because there weren't 
'two vowels so exit the function returning the string value 'Nothing' 

AfterSecondVowel = "Nothing" 

End Function 

這將返回值按您的規範中,只有你沒有指定的是應該如何表現,如果第二個元音是最後一個字母 - 上面只會返回一個空字符串。

2

下面是我的答案。我還添加了邏輯來檢查是否有第二個元音,如果沒有,則會引發錯誤字符串。細節請參見屏幕截圖。

= IF(A1 <> 「」,IFERROR(MID(A1,FIND( 「|」,SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(LOWER(A1), 「一」, 「|」) , 「E」, 「|」)中, 「i」, 「|」), 「O」, 「|」), 「U」, 「|」),FIND( 「|」,SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE (SUBSTITUTE(LOWER(A1), 「一」, 「|」), 「E」, 「|」)中, 「i」, 「|」), 「O」, 「|」), 「U」,「| 「))+ 1)+1,1),」 無 第二個元音發現 「),」「)

enter image description here

+0

Upvoted。用於刷新的問題[這裏](http://stackoverflow.com/q/36978101/641067) – brettdj

0

假設你有一個數據建立這樣的,你的短語開始單元格A1並沿着A列向下:

tigeravatar example for Deeksha Jha

選擇單元格B1和與選定的那個小區,創建一個名爲範圍。我把它命名爲LetterAfterVowel2,並用此公式定義:

=MID($A1,MIN(SEARCH({"a","e","i","o","u","y"},$A1&"aieouy",MIN(SEARCH({"a","e","i","o","u","y"},$A1&"aieouy"))+1))+1,1) 

現在我們不必鍵入亂每一次,它使成品配方乾淨多了。在B1單元格並複製下來是這樣的公式:

=IF(A1="","",IF(LetterAfterVowel2=" ","Nothing",LetterAfterVowel2)) 
相關問題