【问题标题】:Filter out a specific word in Excel Vba过滤掉 Excel Vba 中的特定单词
【发布时间】:2014-04-04 13:43:01
【问题描述】:

我想从字符串中过滤掉特定的单词。 例如, “这是一个样本文件。” 要在 excel vba = "file" 中过滤掉的单词。 请帮助,急需此代码。 谢谢。

【问题讨论】:

    标签: string excel vba filter


    【解决方案1】:

    Instr("This is a sample file.", "file") 将为您提供“文件”在较长字符串中第一次出现的位置,如果不存在则为 0。

    您可以使用Left、Mid 和Right 删除字符串的元素。 Len 为您提供字符串的长度。

    把所有这些放在一起:

    Sub Test()
        Dim s1 As String
        Dim s2 As String
        Dim pos As Integer
    
        s1 = "This is a sample file."
        s2 = "file"
        pos = InStr(s1, s2)
        If pos > 0 Then
            Debug.Print Left(s1, pos - 1) & Mid(s1, pos + Len(s2))
        End If
    End Sub
    

    【讨论】:

      猜你喜欢
      • 2014-10-26
      • 1970-01-01
      • 2019-08-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-19
      • 2017-11-10
      • 2017-10-04
      相关资源
      最近更新 更多