Format cellule colonne B

matrix

XLDnaute Occasionnel
Bonjour à tous,

Dans la colonne B de mon fichier Excel, j'ai des nombres à 4 caractères et à 5 caractères.

Ex. : 1502
1504
11234

Je voudrais que si le nombre a 4 caractères qu'il lui donne le format "00000"

Ex. : 1502 devient 01502
11234 restes 11234, car il a déjà 5 caractères.

De plus, une fois terminé, il met la colonne B en format texte.

Comment faire s.v.p?

Voici le test que j'ai fait jusqu'a maintenant.


Code:
Dim Cel As Range
Dim Plage As Range
Set Plage = Range("B2:B200")
If Plage Is Nothing Then Exit Sub
For Each Cel In Plage
    Cel = Format(Range(Cel), "00000")
Next Cel

Merci pour votre aide

matrix
 

Pierrot93

XLDnaute Barbatruc
Re : Format cellule colonne B

Bonjour Matrix

pas sûr d'avoir tout compris.... peut être ainsi :

Code:
Option Explicit
Sub test()
Dim c As Range
Range("B2:B" & Range("B65536").End(xlUp).Row).NumberFormat = "@"
For Each c In Range("B2:B" & Range("B65536").End(xlUp).Row)
    If Len(c.Value) = 4 Then c.Value = "0" & c.Value
Next c
End Sub

bon après midi
@+
 

Discussions similaires

Statistiques des forums

Discussions
312 492
Messages
2 088 936
Membres
103 987
dernier inscrit
Doctami