simplification de code

Jul74ien74

XLDnaute Nouveau
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
 

Robert

XLDnaute Barbatruc
Repose en paix
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
 

Discussions similaires

Statistiques des forums

Discussions
312 609
Messages
2 090 202
Membres
104 451
dernier inscrit
scp9990