excel - 获取句子中每个单词的首字母(某些关键字除外)

标签 excel excel-formula

我认为这很棘手,但我想听听是否有人有解决方案。

我需要创建一个公式来选取名称列表中每个单词的第一个字母,例如:

the university of electronic science and technology of china

UETC(尽可能避免使用“the”、“of”、“and”、“a”)

到目前为止我尝试过的:

=(LEFT(H2)&MID(H2,FIND("#",SUBSTITUTE(H2&" "," ","#",1))+1,1)&MID(H2,FIND("#",SUBSTITUTE(H2&" "," ","#",2))+1,1))&J2&M2

最佳答案

好问题!我认为最好的选择是使用 VBA 创建自己的函数。将下面的代码添加到 VBA 编辑器中的新模块中,您可以在工作表上使用该函数,如下所示:

=FirstLetters(A1)

根据您的示例,这将返回 UETC

Function FirstLetters(str As String)
    Dim words As Variant
    Dim resultStr As String
    Dim i As Integer

    words = Split(str)
    For i = 0 To UBound(words)
        Select Case words(i)
            Case "the", "of", "and", "a"
                'ignore
            Case Else
                resultStr = resultStr & Left(words(i), 1)
        End Select
    Next i

    FirstLetters = UCase(resultStr)
End Function

关于excel - 获取句子中每个单词的首字母(某些关键字除外),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42050534/

相关文章:

Excel SUMIF 使用由单元格值定义的文本和日期范围

excel - Application.run 有超过 30 个参数

excel - 如何通过将NA视为1来将Excel中的NA(文本NA)值与数字相加

excel - 将一个数字提高到一个数字范围的幂

excel - LocalDB 导出到 Excel

javascript - 如何在 JavaScript 中实现 GROWTH 函数

excel - 查找符合条件的最长字符串 - excel

asp.net - 将 Excel 工作表导入 MS SQL 数据库

sql - 从 Excel 复制/粘贴到 SQL Server 2012 时,Excel 查询中的双引号

vba - 选择单元格中的所有形状