Deleting last sentences in data of a cell

markman2

New Member
Joined
Nov 13, 2009
Messages
12
I have cells that are above the word count, and want to delete the last sentence from them.

For example - (this is my cell content) -

The Quick Brown Fox Jumps Over The Lazy Dog. But this is certainly not the shortest possible pangram. But since it's long we need to do something about this.

I would like it to be trimmed by removing the last sentence, to -

Output:
The Quick Brown Fox Jumps Over The Lazy Dog. But this is certainly not the shortest possible pangram.

Any help would be appreciated, i have over 100k data, and the thought of doing it manually is shaking me up :)
 
Select the range of cells containing the text you want to process and then give this macro a try...

Code:
Sub RemoveAllLastSentences()
  Dim R As Long, C As Long, vArr As Variant
  vArr = Selection
  For R = 1 To UBound(vArr)
    For C = 1 To UBound(vArr, 2)
      If Not IsError(vArr(R, C)) Then
        If Len(vArr(R, C)) > 0 And Not WorksheetFunction.IsNumber(vArr(R, C)) Then
          vArr(R, C) = Left(vArr(R, C), InStrRev(vArr(R, C), ". "))
        End If
      End If
    Next
  Next
  Selection = vArr
End Sub

HOW TO INSTALL MACROs
------------------------------------
If you are new to macros, they are easy to install and use. To install it, simply press ALT+F11 to go into the VB editor and, once there, click Insert/Module on its menu bar, then copy/paste the above code into the code window that just opened up. That's it.... you are done. To use the macro, go back to the worksheet with your data on it and press ALT+F8, select the macro name (RemoveAllLastSentences) from the list that appears and click the Run button. The macro will execute and perform the action(s) you asked for.
 
Upvote 0

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top