set a cell values with 0 at left vba

2.2k views Asked by At

Im trying to introduce a value like "0001" to a cell with vba but all I set is 1 with no 000

this is my code

    Dim iRow As Long
    Dim ws As Worksheet: Set ws = Worksheets(BD_PRODXSIST)

    With ws    
        .Range("A" & iRow).Value = "0001"            
   End With

    Set ws = Nothing
1

There are 1 answers

0
SkyMaster On BEST ANSWER

To insert as text makes use of the apostrophe.

.Range("A" & iRow).Value = "'0001"

Or you can also change the format after entering the number:

.Range("A" & iRow).Value = "1"
.Range("B" & iRow).NumberFormat = "0000"