如何在EXCEL中的字符串中找到第二个元音之后的字符?

时间:2016-04-28 19:25:30

标签: excel excel-vba excel-formula vba

例如,如果我的字符串是

  

快乐之歌

输出应为

  

页。

如果是空白,则显示“Nothing”

4 个答案:

答案 0 :(得分: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),""" |"),& #34; E"" |")," I"" |")," O"&# 34; |")," U"" |"))+ 1)+1,1),"无   第二个元音发现"),"")

enter image description here

答案 1 :(得分: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

答案 2 :(得分: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

这将按照你的规范返回值,只有你没有指定的是如果第二个元音是最后一个字母它应该如何表现 - 上面只会返回一个空字符串。

答案 3 :(得分: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))