Adit2789
Adit2789

Reputation: 159

VBA Deleting words after String

I am trying to delete all words after the first occurrence of an open parentheses in all cells starting from cell D14. I keep coming up with a Object Required error, and not sure where the issue lies.

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

Upvotes: 0

Views: 44

Answers (2)

Adit2789
Adit2789

Reputation: 159

I also ended up fixing it by simply getting rid of the "CompareMethod.Text" entirely

Upvotes: 0

J Reid
J Reid

Reputation: 461

Change CompareMethod.Text to VbCompareMethod.vbTextCompare

Upvotes: 2

Related Questions