Private Sub CommandButton1_Click() Dim derlig As Integer, ligne As String, feuille_desti As String, oui As Boolean Application.ScreenUpdating = False feuille_desti = "Feuil2" ' <<<<<<======== ici le nom de la feuille d'accueil des données derlig = 2 ' <<<========== ici ta ligne de départ sur la feuille (ou détermination par code avec End(XlUp) ) Open "d:\couic.txt" For Input As #1 ' <<<<<<===== ici ton fichier à traiter Do While Not EOF(1) Line Input #1, ligne If Left(ligne, 2) = "MG" Or Not oui Then ajout ligne, derlig, feuille_desti oui = True End If Loop Close #1 Application.ScreenUpdating = True End Sub
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionOption Explicit Private Sub CommandButton1_Click() Dim derlig As Integer, ligne_bonne As String derlig = 2 ligne_bonne = "aaa|bbb|ccc" ajout ligne_bonne, derlig ligne_bonne = "xxx|yyy|zzz|kkk" ajout ligne_bonne, derlig End Sub Private Sub ajout(ByVal toto, ByRef derlig As Integer) Dim titi titi = Split(toto, "|") Range(Cells(derlig, 1), Cells(derlig, UBound(titi) + 1)) = titi derlig = derlig + 1 End Sub
ajout ligne_bonne, derlig
Option Explicit Private Sub CommandButton1_Click() Dim derlig As Integer, ligne As String, feuille_desti As String Application.ScreenUpdating = False feuille_desti = "Feuil2" ' <<<<<<======== ici le nom de la feuille d'accueil des données derlig = 2 ' <<<========== ici ta ligne de départ sur la feuille (ou détermination par code avec End(XlUp) ) Open "d:\couic.txt" For Input As #1 ' <<<<<<===== ici ton fichier à traiter Do While Not EOF(1) Line Input #1, ligne If Left(ligne, 2) = "MG" Then ajout ligne, derlig, feuille_desti End If Loop Close #1 Application.ScreenUpdating = True End Sub Private Sub ajout(ByVal toto, ByRef derlig As Integer, ByVal F As String) Dim titi With Worksheets(F) titi = Split(toto, "|") .Range(.Cells(derlig, 1), .Cells(derlig, UBound(titi) + 1)) = titi derlig = derlig + 1 End With End Sub
Magasin |col |hauteur |adresse | Equipement |Date 1ere mise en service