Maybe try this code
Function IsAtStartOfSentence(ByVal SearchString As String, ByVal SearchRange As Range) As Boolean ' Declare variables Dim StartOfSentence As String Dim FoundPosition As Long ' Define the characters that can precede the start of a sentence StartOfSentence = ".!?;" ' Add any other characters you consider as sentence endings ' Find the position of the search string within the specified range FoundPosition = InStr(SearchRange.Text, SearchString) ' If the search string is not found, return False If FoundPosition = 0 Then IsAtStartOfSentence = False Exit Function End If ' Check if the character preceding the search string is a sentence ending character If FoundPosition > 1 Then If InStr(StartOfSentence, Mid(SearchRange.Text, FoundPosition - 1, 1)) > 0 Then IsAtStartOfSentence = True Else IsAtStartOfSentence = False End If Else ' If the search string is at the very beginning of the range, assume it's at the start of a sentence IsAtStartOfSentence = True End If End Function




Reply With Quote