Removing comma but only if nothing follows it

otictac1

New Member
Joined
Jan 14, 2008
Messages
49
Hello everyone,

Is there anyway to remove a comma, but only in the case where nothing would follow it. I have some data that can come in two varieties. The first:

Data, data

Is just fine the way it is.

The second type:

Data,

Is okay, but would look much neater if I could remove the superflous comma. The data length is variable and I am doing this in a much larger VBA code that will analyze quite a few cells on a worksheet.

Is this possible?

Thanks in advance.
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Hi,

Can this get you started?
Code:
Sub test()
Dim c As Range
Set c = Range("A1")
If Right(c, 1) = "," Then c = Left(c, Len(c) - 1)
End Sub

kind regards,
Erik
 
Upvote 0
Here is some VBA code that loops through a specified range and removes the trailing commas.
Code:
Sub RemoveTrailingCommas()

    Application.ScreenUpdating = False
    
    Dim myRange As Range
    Dim cell As Range
    
'   Set Range to loop through
    Set myRange = Range("A1:A3")

'   Loop through data, updating where necessary
    For Each cell In myRange
        If Right(cell, 1) = "," Then cell = Left(cell, Len(cell) - 1)
    Next cell
    
    Application.ScreenUpdating = True
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,430
Messages
6,119,443
Members
448,898
Latest member
drewmorgan128

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