Macro to run on cells whose cell length is greater than one

Video99

New Member
Joined
Nov 21, 2019
Messages
3
I have a spreadsheet with a number of columns; some contain just a single-digit number or grade (e.g.'B' or '1') and some contain full comments. I would like a macro that adds a full stop/period to the ends of cells that contain comments which are missing a full stop but does not add a full stop to columns which contain just a single letter or number. Has anybody got any idea how to do this ? I've tried googling and I can't get anywhere.

Thanks
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Welcome to posting at MrExcel!

Give this a try with a copy of your workbook.

VBA Code:
Sub AddFullStop()
  Dim c As Range
  
  Application.ScreenUpdating = False
  For Each c In Cells.SpecialCells(xlConstants)
    If Len(c.Value) > 1 Then
      If Right(c.Value, 1) <> "." Then c.Value = c.Value & "."
    End If
  Next c
  Application.ScreenUpdating = True
End Sub
 
Upvote 0
Welcome to posting at MrExcel!

Give this a try with a copy of your workbook.

VBA Code:
Sub AddFullStop()
  Dim c As Range
 
  Application.ScreenUpdating = False
  For Each c In Cells.SpecialCells(xlConstants)
    If Len(c.Value) > 1 Then
      If Right(c.Value, 1) <> "." Then c.Value = c.Value & "."
    End If
  Next c
  Application.ScreenUpdating = True
End Sub
Wow - fantastic ! it worked. Amazing

Thank you so much

Is there any way that it only runs over an area I have highlighted ?
 
Upvote 0
Is there any way that it only runs over an area I have highlighted ?
Try
VBA Code:
Sub AddFullStop_v2()
  Dim c As Range
  
  Application.ScreenUpdating = False
  For Each c In Selection
    If Len(c.Value) > 1 Then
      If Right(c.Value, 1) <> "." Then c.Value = c.Value & "."
    End If
  Next c
  Application.ScreenUpdating = True
End Sub
 
Upvote 0
Solution
Try
VBA Code:
Sub AddFullStop_v2()
  Dim c As Range
 
  Application.ScreenUpdating = False
  For Each c In Selection
    If Len(c.Value) > 1 Then
      If Right(c.Value, 1) <> "." Then c.Value = c.Value & "."
    End If
  Next c
  Application.ScreenUpdating = True
End Sub
Thank you so much ! Worked a dream :)
 
Upvote 0
Cheers. Glad to contribute. Thanks for the follow-up. :)
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,196
Members
452,616
Latest member
intern444

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