Remove trailing zeros

FryGirl

Well-known Member
Joined
Nov 11, 2008
Messages
1,385
Office Version
  1. 365
Platform
  1. Windows
How can I remove the trailing zeros from the inputs below? Everything to the right is what I would like to keep

D000000000 -- D
D0SA000000 -- D0SA
D1A0000000 -- D1A
 
replace Range("A1") with your column

Code:
Public Sub ClearZeros()
Dim i As Integer
Dim iRows As Integer
On Error Resume Next

Range("A1").Select
iRows = ActiveSheet.UsedRange.Rows.Count

While ActiveCell.Row <= iRows
   ActiveCell.Value = Replace(ActiveCell.Value, "0", "")

   ActiveCell.Offset(1, 0).Select     'next row
Wend
End Sub
 
Upvote 0
I don't have the second column. This is what I would like a formula to do.
 
Upvote 0
=left(A1,find(“000”,A1)-1)
Note the double quotes are what’s on your keyboard I am using an iPad so they are different
 
Upvote 0
replace Range("A1") with your column

Code:
Public Sub ClearZeros()
Dim i As Integer
Dim iRows As Integer
On Error Resume Next

Range("A1").Select
iRows = ActiveSheet.UsedRange.Rows.Count

While ActiveCell.Row <= iRows
   ActiveCell.Value = Replace(ActiveCell.Value, "0", "")

   ActiveCell.Offset(1, 0).Select     'next row
Wend
End Sub
Will this not reduce DzeroSA to DSA
 
Upvote 0
How about
Fluff.xlsm
AB
1
2D000000000D
3D0SA000000D0SA
4D1A0000000D1A
Sheet4
Cell Formulas
RangeFormula
B2:B4B2=REGEXREPLACE(A2,"0*$","")
 
Upvote 0
The formula works great. The VBA will reduce D0SA000000 to DSA
 
Upvote 0
Thanks Fluff, but REGEXREPLACE does not work in my 365 version of Excel.
 
Upvote 0
Code:
Public Sub ClearZeros()
Dim vWord
Dim iRows As Integer, i As Integer
On Error Resume Next

Range("A1").Select
iRows = ActiveSheet.UsedRange.Rows.Count

While ActiveCell.Row <= iRows
   vWord = Trim(ActiveCell.Value)
   For i = Len(vWord) To 1 Step -1
     If Mid(vWord, i, 1) <> "0" Then Exit For
   Next
   
   ActiveCell.Value = Left(vWord, i)
   
   ActiveCell.Offset(1, 0).Select     'next row
Wend
End Sub
 
Upvote 0

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