Private Sub cmdExport_Click()
Dim i As Integer
Dim plage As Range
Dim NomFeuille As String
NomFeuille = InputBox("Nom de la nouvelle feuille d'export?", "Exporter des colonnes", "")
For i = 0 To 14
If lbColonnes.Selected(i) Then
With Sheets("Donnees").Range("A1").CurrentRegion
If plage Is Nothing Then
Set plage = .Columns(i + 1)
Else
Set plage = Union(plage, .Columns(i + 1))
End If
End With
End If
Next i
On Error Resume Next
plage.Copy
Sheets.Add
With ActiveSheet
If NomFeuille <> "" Then .Name = NomFeuille
.Range("A1").PasteSpecial skipblanks:=True
[COLOR=red] With .Range("A1").CurrentRegion[/COLOR]
[COLOR=red] [COLOR=yellowgreen]'Ajuster les colonnes au texte[/COLOR]
.Columns.AutoFit[/COLOR]
[COLOR=red] [COLOR=yellowgreen] 'Créer un format conditionnel[/COLOR]
.FormatConditions.Delete[/COLOR]
[COLOR=red] [COLOR=yellowgreen] 'Pour avoir les lignes paires grisées, changer 1 par 0 dans la formule[/COLOR]
.FormatConditions.Add Type:=xlExpression, Formula1:="=MOD(LIGNE();2)=1"[/COLOR]
[COLOR=red] [COLOR=yellowgreen]'Couleur d'écriture[/COLOR]
.FormatConditions(1).Font.ColorIndex = xlAutomatic[/COLOR]
[COLOR=red] [COLOR=yellowgreen]'Couleur de fond[/COLOR]
.FormatConditions(1).Interior.ColorIndex = 15
End With
[/COLOR] End With
Application.CutCopyMode = False
If Err.Number > 0 Then
MsgBox "Une erreur c'est produite lors de l'exportation des colonnes" & vbCrLf _
& Err.Description, vbExclamation, "Exportation colonnes"
Else
MsgBox "Exportation réussie sur la feuille " & ActiveSheet.Name, vbInformation, "Exportation colonnes"
End If
Unload Me
End Sub