Created
July 19, 2017 10:28
-
-
Save ManUtopiK/2b3991914c237ac98a8ff91a9cf9af3e to your computer and use it in GitHub Desktop.
Import csv vers xls
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sub Csv() | |
Dim Fichier As Variant, Chaine As String, T(), LDéb As Long, TSpl() As String, L As Long, C As Long, Z As String | |
ReDim T(1 To 5000, 1 To 9) | |
LDéb = 2 | |
ChDrive ThisWorkbook.Path: ChDir ThisWorkbook.Path | |
Fichier = Application.GetOpenFilename("Fichier CSV (*.csv), *.csv") | |
If VarType(Fichier) <> vbString Then Exit Sub | |
Open Fichier For Input As #1 | |
Line Input #1, Chaine ' ignore la ligne de titres du csv | |
Do While Not EOF(1) | |
Line Input #1, Chaine | |
TSpl = Split(Chaine, ";") | |
If L > 0 Then If TSpl(0) <> T(L, 1) Or TSpl(1) <> T(L, 2) Then GoSub Total | |
L = L + 1 | |
For C = 1 To 9 | |
Z = TSpl(Choose(C, 1, 2, 4, 9, 12, 22, 27, 32, 37) - 1) | |
If IsNumeric(Z) Then T(L, C) = CDbl(Z) Else T(L, C) = Z | |
Next C: Loop | |
GoSub Total | |
Close #1 | |
Feuil1.Rows("2:5001").Delete | |
Feuil1.Cells(2, 1).Resize(L, 9).Value2 = T | |
Dim A As Range, Cel As Range | |
For Each A In Feuil1.Columns("I").SpecialCells(xlCellTypeFormulas, 1) | |
For Each Cel In A | |
Cel.FormulaR1C1 = "=SUBTOTAL(9,R" & Cel.Value & "C:R[-1]C)" | |
Cel.Offset(, -1).HorizontalAlignment = xlRight: Next Cel, A | |
Exit Sub | |
Total: | |
L = L + 1: T(L, 8) = "Total": T(L, 9) = "=" & LDéb | |
If EOF(1) Then Return | |
L = L + 1: LDéb = L + 2: Return | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment