simplification de code

  • Initiateur de la discussion Initiateur de la discussion Jul74ien74
  • Date de début Date de début

Boostez vos compétences Excel avec notre communauté !

Rejoignez Excel Downloads, le rendez-vous des passionnés où l'entraide fait la force. Apprenez, échangez, progressez – et tout ça gratuitement ! 👉 Inscrivez-vous maintenant !

J

Jul74ien74

Guest
Bonjour,

je voudrais savoir si ce code peut etre simplifié dans le sens ou je voudrais mettre : si dans chaque ligne de la colonne "D" les mots ....... sont present alors fais ceci sinon passe a la ligne suivante.


Sub AfficherInfoFichier()
For Lig = 8 To 10
If Cells(Lig, 4).Value = "1_01_Room-Layout\" Then
FichierATester = [M2] + Cells(Lig, 4) + Cells(Lig, 8)

Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFile(FichierATester)


Cells(Lig, 10).Value = f.DateLastModified

End If
Next Lig

For Lig = 13 To 21
If Cells(Lig, 4).Value = "1_02_Desk-Layout\" Then
FichierATester = [M2] + Cells(Lig, 4) + Cells(Lig, 8)

Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFile(FichierATester)


Cells(Lig, 10).Value = f.DateLastModified

End If
Next Lig


For Lig = 24 To 30
If Cells(Lig, 4).Value = "1_03_Rack-Layout\" Then
FichierATester = [M2] + Cells(Lig, 4) + Cells(Lig, 8)

Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFile(FichierATester)


Cells(Lig, 10).Value = f.DateLastModified

End If

Next Lig

For Lig = 33 To 40
If Cells(Lig, 4).Value = "1_04_Blockdiagram\" Then
FichierATester = [M2] + Cells(Lig, 4) + Cells(Lig, 8)

Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFile(FichierATester)


Cells(Lig, 10).Value = f.DateLastModified


End If

Next Lig
For Lig = 45 To 63
If Cells(Lig, 4).Value = "2_01_Video\" Then
FichierATester = [M2] + Cells(Lig, 4) + Cells(Lig, 8)

Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFile(FichierATester)


Cells(Lig, 10).Value = f.DateLastModified


End If
Next Lig
For Lig = 66 To 75
If Cells(Lig, 4).Value = "2_02_Audio\" Then
FichierATester = [M2] + Cells(Lig, 4) + Cells(Lig, 8)

Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFile(FichierATester)


Cells(Lig, 10).Value = f.DateLastModified


End If
Next Lig
For Lig = 78 To 80
If Cells(Lig, 4).Value = "2_03_Pilotage\" Then
FichierATester = [M2] + Cells(Lig, 4) + Cells(Lig, 8)

Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFile(FichierATester)


Cells(Lig, 10).Value = f.DateLastModified


End If
Next Lig
For Lig = 85 To 120
If Cells(Lig, 4).Value = "3_01_Patchfields\" Then
FichierATester = [M2] + Cells(Lig, 4) + Cells(Lig, 8)

Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFile(FichierATester)


Cells(Lig, 10).Value = f.DateLastModified


End If
Next Lig
For Lig = 127 To 161
If Cells(Lig, 4).Value = "4_01_Constructions\" Then
FichierATester = [M2] + Cells(Lig, 4) + Cells(Lig, 8)

Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFile(FichierATester)


Cells(Lig, 10).Value = f.DateLastModified


End If
Next Lig

End Sub
 
Re : simplification de code

Bonjour Julien, bonjour le forum,

Peut-être comme ça :

Code:
Private Lig As Byte


Sub AfficherInfoFichier()
For Lig = 8 To 10
    If Cells(Lig, 4).Value = "1_01_Room-Layout\" Then Call suite 'si quand la condition est vrai le code doit s'arrêter alors : The Call suite: Exit Sub
Next Lig
For Lig = 13 To 21
    If Cells(Lig, 4).Value = "1_02_Desk-Layout\" Then Call suite
Next Lig
For Lig = 24 To 30
    If Cells(Lig, 4).Value = "1_03_Rack-Layout\" Then Call suite
Next Lig
For Lig = 33 To 40
    If Cells(Lig, 4).Value = "1_04_Blockdiagram\" Then Call suite
Next Lig
For Lig = 45 To 63
    If Cells(Lig, 4).Value = "2_01_Video\" Then Call suite
Next Lig
For Lig = 66 To 75
    If Cells(Lig, 4).Value = "2_02_Audio\" Then Call suite
Next Lig
For Lig = 78 To 80
    If Cells(Lig, 4).Value = "2_03_Pilotage\" Then Call suite
Next Lig
For Lig = 85 To 120
    If Cells(Lig, 4).Value = "3_01_Patchfields\" Then Call suite
Next Lig
For Lig = 127 To 161
    If Cells(Lig, 4).Value = "4_01_Constructions\" Then Call suite
Next Lig
End Sub


Sub suite()
Dim FichierATester As sting

FichierATester = [M2] + Cells(Lig, 4) + Cells(Lig, 8)
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFile(FichierATester)
Cells(Lig, 10).Value = f.DateLastModified
End Sub
 
- Navigue sans publicité
- Accède à Cléa, notre assistante IA experte Excel... et pas que...
- Profite de fonctionnalités exclusives
Ton soutien permet à Excel Downloads de rester 100% gratuit et de continuer à rassembler les passionnés d'Excel.
Je deviens Supporter XLD
Assurez vous de marquer un message comme solution pour une meilleure transparence.

Discussions similaires

Réponses
4
Affichages
731
Réponses
5
Affichages
839
Réponses
4
Affichages
692
Réponses
4
Affichages
262
Réponses
2
Affichages
439
Réponses
35
Affichages
2 K
Retour