VBA: Add period to end of sentence

FryGirl

Well-known Member
Joined
Nov 11, 2008
Messages
1,225
Office Version
  1. 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:

Some videos you may like

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
53,012
Office Version
  1. 365
Platform
  1. Windows
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
 

FryGirl

Well-known Member
Joined
Nov 11, 2008
Messages
1,225
Office Version
  1. 2016
Platform
  1. Windows
Wonderful. Works great and thank you Fluff.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
53,012
Office Version
  1. 365
Platform
  1. Windows
You're welcome & thanks for the feedback
 

Watch MrExcel Video

Forum statistics

Threads
1,122,737
Messages
5,597,826
Members
414,180
Latest member
Sir Khaya

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
Top