View Full Version : Solved: Delete Dash on each cell
parscon
04-05-2012, 07:32 AM
I have some data in Column A like
1243434-
1132334-24434343-
32323232-434343-
I want delete the dash - in end of numbers that mean will be
1243434
1132334-24434343
32323232-434343
How can i do this by VBA code ?
THank you so much .
shrivallabha
04-05-2012, 08:07 AM
You can do this using Excel formula.
If your data starts from A1 then in B1 put this formula and copy down
=IF(RIGHT(A1,1)="-",LEFT(A1,LEN(A1)-1),A1)
Edit: If you still need VBA then let us know.
parscon
04-05-2012, 08:09 AM
Thank you so much , How can i use this as VBA code ?
Paul_Hossler
04-05-2012, 08:09 AM
Pretty brute force
Sub DeleteTrailingDash()
Dim rCell As Range
Application.ScreenUpdating = False
For Each rCell In ActiveSheet.Range("A1:A12").Cells '<<< change to suit
With rCell
If Right(.Value, 1) = "-" Then .Value = Left(.Value, Len(.Value) - 1)
End With
Next rCell
Application.ScreenUpdating = True
End Sub
Paul
parscon
04-05-2012, 08:21 AM
Really Tank you so much - it is very big help for me .
jay20aiii
04-05-2012, 08:23 AM
Here's another quick function:
Just adjust the cell Worksheet and range to suit your form.
Sub Trim()
For Each c In Worksheets("Sheet1").Range("A1:A3").Cells
If Right(c.Value, 1) = "-" Then
c.Value = Mid(c.Value, 1, Len(c) - 1)
End If
Next
End Sub
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.