Removing trailing zero from values in column?

XcelNoobster

New Member
Joined
Jun 7, 2022
Messages
40
So I have column b that are revisions. A revision is either a letter, a number or a dash. But for some reason, some revisions have an extra trailing zero. How would I loop through each value in column b and remove the zero if the character before it is a letter, a number or a dash?
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
How revision level 10 (the one after 9) would be normally represented in that cell?
 
Upvote 0
Try this macro:
VBA Code:
Sub NoEndZero()
Dim WArr, mySet As String, wLen As Long, I As Long
'
Sheets("Sheet1").Select             '<<< The sheet to be cleaned
'
mySet = "QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm12345678990-"
WArr = Range(Cells(1, "B"), Cells(Rows.Count, "B").End(xlUp)).Value
For I = 1 To UBound(WArr)
    wLen = Len(WArr(I, 1))
    If wLen > 1 Then
        If Right(WArr(I, 1), 1) = "0" Then
            If InStr(1, mySet, Mid(WArr(I, 1), wLen - 1, 1), vbTextCompare) > 0 Then
                WArr(I, 1) = Left(WArr(I, 1), wLen - 1)
            End If
        End If
    End If
Next I
Range("B1").Resize(UBound(WArr), 1).Value = WArr
End Sub
Copy it into a standard module of your vba project, edit the line marked <<<, then execute the macro after having created TWO ;) backup copies of your document
 
Upvote 0
Another option?

VBA Code:
Sub Zap_Zeroes()
    With Range("B2", Cells(Rows.Count, "B").End(xlUp))
        .Replace 0, ""
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,239
Messages
6,170,947
Members
452,368
Latest member
jayp2104

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