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 51 52 53 54 55 56 57 58 59 60 61
|
Sub CommandButton1_Click()
'déclaration des varriables
Dim LastLig As Long
Dim A As Variant
Application.ScreenUpdating = False
A = Application.GetOpenFilename("Text Files (*.txt), *.txt")
If A = False Then
'msg box négatif
MsgBox " Aucun fichier n'a été selectionné"
Else
'suppression de mes graphique existant sur la feuille
For Each Legraph In ActiveSheet.ChartObjects
Legraph.Delete
Next
'importer deux colonne d'auprés un fichier text séparer en virgules
Workbooks.OpenText Filename:=A, Origin:=xlMSDOS, StartRow:=1, _
DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=True, Comma:=False, _
Space:=False, Other:=False, FieldInfo:=Array(Array(1, 1), Array(2, 1), _
Array(3, 1), Array(4, 1), Array(5, 1)), TrailingMinusNumbers:=True
With ActiveWorkbook
With .Worksheets(1)
LastLig = .Cells(.Rows.Count, "C").End(xlUp).Row
.Range("C5:D" & LastLig).Copy _
ThisWorkbook.ActiveSheet.Range("A3")
End With
.Close False
End With
'traçer mon graphique dont l'axe des x est mis dans la colonne A à partir de la troixiéme ligne et celui des Y dans la colonne B à partire de la 3éme ligne aussi
Dim LastLiga As Long
Dim x, Y
Application.ScreenUpdating = False
With ActiveSheet 'A adapter
LastLiga = .Cells(.Rows.Count, 1).End(xlUp).Row
x = .Range("A3:A" & LastLig)
Y = .Range("B3:B" & LastLig)
With .ChartObjects.Add(200, 53, 670, 360).Chart
.ChartType = xlLine
With .SeriesCollection.NewSeries
.XValues = x
.Values = Y
End With
End With
End With
End If
'nommer mon graphe du méme nom de celui de la feuille
ActiveSheet.ChartObjects(1).Name = ActiveSheet.Name
Exit Sub
End Sub |
Partager