Reputation: 265
I want to remove in Excel the first zeros from the following codes, the problem is that the zeros don't have the same pattern. What can I do to achieve this?
The codes before: 0000450D 00320A 0000107B 023B
I want the codes to be like this: 450D 320A 107B 23B
Any ideas? Thanks!
Upvotes: 0
Views: 109
Reputation: 406
If you're happy to use VBA, insert the code below into a new module and on your sheet, use the function like =ReplaceZeros(A1)
Public Function ReplaceZeros(varVal As String)
varLeading = True
For i = 1 To Len(varVal)
If Mid(varVal, i, 1) = "0" Then
If varLeading = False Then
varOutput = varOutput & Mid(varVal, i, 1)
End If
ElseIf Mid(varVal, i, 1) = " " Then
varLeading = True
varOutput = varOutput & Mid(varVal, i, 1)
Else
varLeading = False
varOutput = varOutput & Mid(varVal, i, 1)
End If
Next
ReplaceZeros = varOutput
End Function
This will simply cycle through the characters and remove leading zeroes from the start of the string, or following a space
Upvotes: 1