VBA删除字符串后的单词

时间:2016-10-11 19:13:43

标签: excel vba

我试图在从单元格D14开始的所有单元格中首次出现打开括号后删除所有单词。我不断提出一个Object Required错误,并且不确定问题出在哪里。

Dim startRow As Integer
Dim pos_of_parenth As Integer
Dim resultString as String

startRow = 15

With Windows(NewTemplateName)
    .Activate
    .ActiveSheet.Range("D" & startRow).Select
    Do While .ActiveSheet.Range("D" & startRow).Value <> ""
        resultString = ""
        pos_of_parenth = InStr(1, ActiveSheet.Range("D" & startRow).Text, "(", CompareMethod.Text)
        resultString = Left(.ActiveSheet.Range("D" & startRow).Value, pos_of_parenth)
        startRow = startRow + 1
    Loop
End With

2 个答案:

答案 0 :(得分:2)

CompareMethod.Text更改为VbCompareMethod.vbTextCompare

答案 1 :(得分:0)

我最终还是通过完全摆脱“CompareMethod.Text”

来修复它