• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

trouble with vba trim code

RAM72

Member
Hi All

I have a worksheet that comes from an interface but the issue I need to trim the whole sheet .

I need text number as it is but on applying code It removes 0001223 to1223
which cause me a lot trouble for doing updating and cross matching.

Can anyone advise a solution to this as per attached .

Code:
Sub trim()
Dim cell As Range
For Each cell In ActiveSheet.UsedRange.SpecialCells(xlCellTypeConstants)
cell = WorksheetFunction.trim(cell)
Next cell
End Sub
 

Attachments

  • trim test.xlsx
    15.3 KB · Views: 2
To preserve the leading 0's, format all your cells (or at least the columns of interest) to Text before running the code.
 
Back
Top