merci Bruno
j'ai trouve
en fait ton code initial fonctionnait très bien. c'est mon fichier test qui avait un problème
voici donc le code qui fonctionne chez moi
merci bcp ; sans ton aide j'étais bloqué
BONNES VACANCES
***
Option Explicit
Dim I, II, III, IV
Dim Ws As Worksheet
Dim WsBL As Worksheet
Dim WsPLBL As Worksheet
Dim WsCM As Object
Dim WsMR As Worksheet
Sub NEWblmobile()
I = 0: II = 0: III = 0: IV = 0
Application.ScreenUpdating = False
With ActiveWorkbook
.Unprotect ("")
For Each Ws In .Worksheets
With Ws
Select Case True
Case .Name Like "Mobile BL*"
I = I + 1
Case .Name Like "Packing List BL*"
II = II + 1
Case .Name Like "Mobile CM*"
III = III + 1
Case .Name Like "Mobile MR*"
IV = IV + 1
End Select
End With
Next Ws
.Sheets("Mobile BL1").Copy after:=.Sheets(.Sheets.Count)
Set WsBL = ActiveSheet
With WsBL
.Name = "Mobile BL" & 1 + I
End With
.Sheets("Packing List BL1").Copy after:=.Sheets(.Sheets.Count)
Set WsPLBL = ActiveSheet
With WsPLBL
.Name = "Packing List BL" & 1 + II
.UsedRange.Replace What:="Mobile BL" & II, Replacement:=WsBL.Name, LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
End With
Sheets("Mobile CM1").Unprotect
.Sheets("Mobile CM1").Copy after:=.Sheets(.Sheets.Count)
Set WsCM = ActiveSheet
With WsCM
.Name = "Mobile CM" & 1 + III
.UsedRange.Replace What:="Mobile BL" & II, Replacement:=WsBL.Name, LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
End With
Sheets("Mobile MR1").Unprotect
.Sheets("Mobile MR1").Copy after:=.Sheets(.Sheets.Count)
Set WsMR = ActiveSheet
With WsMR
.Name = "Mobile MR" & 1 + IV
.UsedRange.Replace What:="Mobile BL" & IV, Replacement:=WsBL.Name, LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
End With
End With
Application.ScreenUpdating = True
ActiveWorkbook.Protect ("")
End Sub
***