1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
| Public nbcol As Integer
Public nbligne As Integer
Sub formater_colonnes()
Application.ScreenUpdating = False
'Effacer les espaces avant et après chaque chaîne
For Each cellule In ActiveSheet.UsedRange
cellule.Value = Trim(cellule.Value)
Next
Cells(1, 1).Select
'format texte
Cells.Select
Selection.NumberFormat = "@"
Cells(1, 1).Select
nbcol = WorksheetFunction.CountA(Rows(1))
nbligne = WorksheetFunction.CountA(Columns(1))
Dim val
val = Array(, 28, 37, 46, 55, 64, 73, 82, 91, 100, 109, 118, 127, 136, 145, _
154, 163, 172, 181, 190, 199, 208, 217, 226, 235)
Dim espace As String
Dim temp_valeur As String
Dim new_valeur As String
Dim nb_espace As Integer
Dim test As String
For j = 1 To nbcol - 1
Cells(1, j + 1).Select
For i = 1 To nbligne
nb_espace = val(j)
espace = String(nb_espace, " ") ' Renvoie x espaces, x etant = val.
temp_valeur = ActiveCell.Value
test = espace + temp_valeur
ActiveCell.Value = espace + temp_valeur
ActiveCell.Offset(1, 0).Select
Next i
Next j
'ajuster
Cells.Select
Range("B1").Activate
Cells.EntireColumn.AutoFit
Cells(1, 1).Select
End Sub |
Partager