VBA: Add period to end of sentence
Results 1 to 4 of 4

Thread: VBA: Add period to end of sentence
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    Board Regular
    Join Date
    Nov 2008
    Posts
    989
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default VBA: Add period to end of sentence

    This works well, but curios, can this be done without looping? Such as with Evaluate?

    Code:
    SubAddPeriod()
        Dim c As Range
        For Each c In Range("C8",Range("C" & Rows.Count).End(xlUp))
            If PeriodExists(c) <> True Then
                If Len(c) > 0 And Right(c, 1)<> "." Then c = c & "."
            End If
        Next c
    EndSub

    Code:
    FunctionPeriodExists(ByVal Rng As Range) As Boolean
        If InStr(Rng.Value, ".") Then
            PeriodExists = True
        End If
    EndFunction
    Last edited by FryGirl; Aug 20th, 2019 at 10:42 AM.

  2. #2
    MrExcel MVP
    Moderator
    Fluff's Avatar
    Join Date
    Jun 2014
    Location
    Chippenham
    Posts
    27,051
    Post Thanks / Like
    Mentioned
    461 Post(s)
    Tagged
    46 Thread(s)

    Default Re: VBA: Add period to end of sentence

    How about
    Code:
    Sub FryGirl()
        With Range("C8", Range("C" & Rows.Count).End(xlUp))
           .Value = Evaluate(Replace("if(len(@)=0,"""",if(right(@)=""."",@,@&"".""))", "@", .Address))
          End With
    End Sub
    - Posting Data try one of these tools
    - Posting guidelines, forum rules and terms of use
    - Read the FAQs

    Running Office 365 on Win 10

  3. #3
    Board Regular
    Join Date
    Nov 2008
    Posts
    989
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default Re: VBA: Add period to end of sentence

    Wonderful. Works great and thank you Fluff.

  4. #4
    MrExcel MVP
    Moderator
    Fluff's Avatar
    Join Date
    Jun 2014
    Location
    Chippenham
    Posts
    27,051
    Post Thanks / Like
    Mentioned
    461 Post(s)
    Tagged
    46 Thread(s)

    Default Re: VBA: Add period to end of sentence

    You're welcome & thanks for the feedback
    - Posting Data try one of these tools
    - Posting guidelines, forum rules and terms of use
    - Read the FAQs

    Running Office 365 on Win 10

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •