VBA: Add period to end of sentence

FryGirl

Well-known Member
Joined
Nov 11, 2008
Messages
1,368
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
This works well, but curios, can this be done without looping? Such as with Evaluate?

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

Code:
[FONT="Arial"][COLOR=#000000]FunctionPeriodExists(ByVal Rng As Range) As Boolean[/COLOR][/FONT]
[FONT="Arial"][COLOR=#000000]    If InStr(Rng.Value, ".") Then[/COLOR][/FONT]
[FONT="Arial"][COLOR=#000000]        PeriodExists = True[/COLOR][/FONT]
[FONT="Arial"][COLOR=#000000]    End If[/COLOR][/FONT]
[FONT="Arial"][COLOR=#000000]EndFunction[/COLOR][/FONT]
 
Last edited:

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
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
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,242
Members
452,623
Latest member
russelllowellpercy

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