decadence
Well-known Member
- Joined
- Oct 9, 2015
- Messages
- 525
- Office Version
- 365
- 2016
- 2013
- 2010
- 2007
- Platform
- Windows
Hi, I am trying to delete the length of a word if multiple specific text is found in a cell, but the code I have deletes the whole string rather than just the length of the word which is variable, Can someone help.
Example:
The multiple specific text I am trying to find is Pie and Split
<tbody>
</tbody>
Then Delete the Length of the word before the text found
<tbody>
</tbody>
Code:
Dim c As range
For Each c In Selection
If InStr(c.value, " Pie") > 0 Then
c.value = Left(c.value, InStr(c.value, " Pie") - 1)
End If
If InStr(c.value, "Pie") > 0 Then
c.value = Left(c.value, InStr(c.value, "Pie") - 1)
End If
If InStr(c.value, " Split") > 0 Then
c.value = Left(c.value, InStr(c.value, " Split") - 1)
End If
If InStr(c.value, "Split") > 0 Then
c.value = Left(c.value, InStr(c.value, "Split") - 1)
End If
Next c
End Sub
Example:
The multiple specific text I am trying to find is Pie and Split
Something MyApple Pie Something |
Something YourApple Pie Something |
Something TheirApplePie Something |
Something Banana Split Something |
Something BananasSplit Something |
<tbody>
</tbody>
Then Delete the Length of the word before the text found
Something Something |
Something Something |
Something Something |
Something Something |
Something Something |
<tbody>
</tbody>
Last edited: