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 !
Sub travdem()
Dim cellule As Range
Dim nomfeuille1 As String, nomfeuille2 As String
Dim valmax As Currency, valmin As Currency
Dim def As Boolean
' pour boucler sur la colonne 1
valmax = 185
valmin = 175
'La température limite inférieure est de 175°.
'La température limite supérieure est de 185°
nomfeuille1 = "Données"
nomfeuille2 = "Récapitulatif"
Sheets(nomfeuille2).UsedRange.Offset(1).Clear
With Sheets(nomfeuille1)
For Each cellule In .Range("b2:b" & .Cells(Columns(2).Cells.Count, 1).End(xlUp).Row)
If cellule.Value < valmin Or cellule.Value > valmax Then def = True
If def = False Then
If cellule.Offset(0, 1).Value < valmin Or cellule.Offset(0, 1).Value > valmax Then def = True
End If
If def = True Then
.Rows(cellule.Row).Copy _
Destination:=Sheets(nomfeuille2).Rows(Sheets(nomfeuille2).Range("a65536").End(xlUp).Row + 1)
def = False
End If
Next cellule
End With
End Sub
Option Base 1
Sub Ecarts()
Dim tablo, tablo1$(), tablo2$(), i&, j As Byte, v As Double, n&
tablo = Sheets("Données").Range("A2:C" & Sheets("Données").Range("A65536").End(xlUp).Row)
ReDim tablo1(UBound(tablo))
'---remplissage de tablo1 et tablo2---
For i = 1 To UBound(tablo)
For j = 2 To 3
v = Val(Replace(tablo(i, j), ",", "."))
If v And (v < 175 Or v > 185) Then
n = n + 1
tablo1(i) = "T" & j - 1 & IIf(v < 175, " - " & 175 - v, " + " & v - 185)
ReDim Preserve tablo2(4, n)
tablo2(1, n) = Trim(tablo(i, 1))
tablo2(2, n) = tablo(i, 2)
tablo2(3, n) = tablo(i, 3)
tablo2(4, n) = tablo1(i)
End If
Next
Next
'---transfert vers les feuilles---
With Sheets("Données").Range("D2:D65536")
.ClearContents
.Resize(UBound(tablo)) = Application.Transpose(tablo1)
End With
With Sheets("Récapitulatif").Range("A2:D65536")
.ClearContents
.Resize(n) = Application.Transpose(tablo2)
.Replace ",", ".", LookAt:=xlPart 'convertit en valeurs numériques (colonnes B et C)
End With
End Sub
Bonsoir
Ci dessous un code à tester
Code:Sub travdem() Dim cellule As Range Dim nomfeuille1 As String, nomfeuille2 As String Dim valmax As Currency, valmin As Currency Dim def As Boolean ' pour boucler sur la colonne 1 valmax = 185 valmin = 175 'La température limite inférieure est de 175°. 'La température limite supérieure est de 185° nomfeuille1 = "Données" nomfeuille2 = "Récapitulatif" Sheets(nomfeuille2).UsedRange.Offset(1).Clear With Sheets(nomfeuille1) For Each cellule In .Range("b2:b" & .Cells(Columns(2).Cells.Count, 1).End(xlUp).Row) If cellule.Value < valmin Or cellule.Value > valmax Then def = True If def = False Then If cellule.Offset(0, 1).Value < valmin Or cellule.Offset(0, 1).Value > valmax Then def = True End If If def = True Then .Rows(cellule.Row).Copy _ Destination:=Sheets(nomfeuille2).Rows(Sheets(nomfeuille2).Range("a65536").End(xlUp).Row + 1) def = False End If Next cellule End With End Sub
JP
Option Base 1
Sub Ecarts()
Dim F As Worksheet, tablo, tablo1$(), tablo2$(), i&, j As Byte, v As Double, n&
[COLOR="Red"]Sheets("Récapitulatif").Range("A2:D65536").ClearContents[/COLOR]
For Each F In Worksheets
If F.Name <> "Récapitulatif" Then
tablo = F.Range("A2:C" & F.Range("A65536").End(xlUp).Row)
ReDim tablo1(UBound(tablo))
n = 0
'---remplissage des tablo1 et tablo2---
For i = 1 To UBound(tablo)
For j = 2 To 3
v = Val(Replace(tablo(i, j), ",", "."))
If v And (v < 175 Or v > 185) Then
n = n + 1
tablo1(i) = "T" & j - 1 & IIf(v < 175, " - " & 175 - v, " + " & v - 185)
ReDim Preserve tablo2(4, n)
tablo2(1, n) = Trim(tablo(i, 1))
tablo2(2, n) = tablo(i, 2)
tablo2(3, n) = tablo(i, 3)
tablo2(4, n) = tablo1(i)
End If
Next
Next
'---transfert vers les feuilles---
With F.Range("D2:D65536")
.ClearContents
.Resize(UBound(tablo)) = Application.Transpose(tablo1)
End With
With [COLOR="red"]Sheets("Récapitulatif").Range("A65536").End(xlUp)(2).Resize(n, 4)[/COLOR]
[COLOR="Red"].Offset(, 4).Resize(1, 1) = F.Name 'indique la feuille en colonne E[/COLOR]
.Value = Application.Transpose(tablo2)
.Replace ",", ".", LookAt:=xlPart 'convertit en valeurs numériques (colonnes B et C)
End With
End If
Next
End Sub
Sub travdem()
Dim cellule As Range
Dim nomfeuille1 As String, nomfeuille2 As String
Dim valmax As Currency, valmin As Currency
Dim def As Boolean
' pour boucler sur la colonne 1
valmax = 185
valmin = 175
'La température limite inférieure est de 175°.
'La température limite supérieure est de 185°
nomfeuille1 = ActiveSheet.Name
nomfeuille2 = "Récapitulatif"
'Sheets(nomfeuille2).UsedRange.Offset(1).Clear
With Sheets(nomfeuille2)
.Range("a" & .Range("a65536").End(xlUp).Row + 1) = nomfeuille1
End With
With Sheets(nomfeuille1)
For Each cellule In .Range("b2:b" & .Cells(Columns(2).Cells.Count, 1).End(xlUp).Row)
If IsNumeric(cellule) Then
If cellule.Value < valmin Or cellule.Value > valmax Then
def = True
cellule.Offset(0, 2) = "T1 " & IIf(CCur(cellule.Value) < 175, " - " & 175 - CCur(cellule.Value), " + " & CCur(cellule.Value) - 185)
End If
If def = False Then
If cellule.Offset(0, 1).Value < valmin Or cellule.Offset(0, 1).Value > valmax Then
def = True
cellule.Offset(0, 2) = "T2 " & IIf(CCur(cellule.Offset(0, 1).Value) < 175, " - " & 175 - CCur(cellule.Offset(0, 1).Value), " + " & CCur(cellule.Offset(0, 1).Value) - 185)
End If
End If
If def = True Then
.Rows(cellule.Row).Copy _
Destination:=Sheets(nomfeuille2).Rows(Sheets(nomfeuille2).Range("a65536").End(xlUp).Row + 1)
def = False
End If
End If
Next cellule
End With
With Sheets(nomfeuille2)
.Range("a" & .Range("a65536").End(xlUp).Row + 1) = " "
End With
End Sub
Le dernier perfectionnement à apporter, serait de n'afficher que les données erronées dans le récapitulatif.
Option Base 1
Sub Ecarts()
Dim F As Worksheet, tablo, tablo1$(), tablo2$(), i&, j As Byte, v As Double, n&
Sheets("Récapitulatif").Range("A2:D65536").ClearContents
For Each F In Worksheets
If F.Name <> "Récapitulatif" Then
tablo = F.Range("A2:C" & F.Range("A65536").End(xlUp).Row)
ReDim tablo1(UBound(tablo))
n = 0
'---remplissage des tablo1 et tablo2---
For i = 1 To UBound(tablo)
For j = 2 To 3
v = Val(Replace(tablo(i, j), ",", "."))
If v And (v < 175 Or v > 185) Then
n = n + 1
tablo1(i) = "T" & j - 1 & IIf(v < 175, " - " & 175 - v, " + " & v - 185)
ReDim Preserve tablo2(4, n)
tablo2(1, n) = Trim(tablo(i, 1))
[COLOR="Red"] If v < 175 Then tablo2(2, n) = tablo(i, 2) Else tablo2(3, n) = tablo(i, 3)[/COLOR]
tablo2(4, n) = tablo1(i)
End If
Next
Next
'---transfert vers les feuilles---
With F.Range("D2:D65536")
.ClearContents
.Resize(UBound(tablo)) = Application.Transpose(tablo1)
End With
With Sheets("Récapitulatif").Range("A65536").End(xlUp)(2).Resize(n, 4)
.Offset(, 4).Resize(1, 1) = F.Name 'indique la feuille en colonne E
.Value = Application.Transpose(tablo2)
.Replace ",", ".", LookAt:=xlPart 'convertit en valeurs numériques (colonnes B et C)
End With
End If
Next
End Sub
Option Base 1
Sub Ecarts()
Dim F As Worksheet, tablo, tablo1$(), tablo2$(), i&, j As Byte, v As Double, n&
Sheets("Récapitulatif").Range("[COLOR="Red"]A2:E65536[/COLOR]").ClearContents
For Each F In Worksheets
If F.Name <> "Récapitulatif" Then
tablo = F.Range("A2:C" & F.Range("A65536").End(xlUp).Row)
ReDim tablo1(UBound(tablo))
n = 0
'---remplissage des tablo1 et tablo2---
For i = 1 To UBound(tablo)
For j = 2 To 3
v = Val(Replace(tablo(i, j), ",", "."))
If v And (v < 175 Or v > 185) Then
n = n + 1
tablo1(i) = "T" & j - 1 & IIf(v < 175, " - " & 175 - v, " + " & v - 185)
ReDim Preserve tablo2(4, n)
tablo2(1, n) = Trim(tablo(i, 1))
[COLOR="Red"]If j = 2 Then tablo2(2, n) = tablo(i, 2)
If j = 3 Then tablo2(3, n) = tablo(i, 3)[/COLOR]
tablo2(4, n) = tablo1(i)
End If
Next
Next
'---transfert vers les feuilles---
With F.Range("D2:D65536")
.ClearContents
.Resize(UBound(tablo)) = Application.Transpose(tablo1)
End With
With Sheets("Récapitulatif").Range("A65536").End(xlUp)(2).Resize(n, 4)
.Offset(, 4).Resize(1, 1) = F.Name 'indique la feuille en colonne E
.Value = Application.Transpose(tablo2)
.Replace ",", ".", LookAt:=xlPart 'convertit en valeurs numériques (colonnes B et C)
End With
End If
Next
End Sub
Option Base 1
Sub Ecarts()
Dim F As Worksheet, tablo, tablo1$(), tablo2$(), i&, j As Byte, v As Double, n&
Sheets("Récapitulatif").Range("A2:E65536").ClearContents
For Each F In Worksheets
If F.Name <> "Récapitulatif" Then
tablo = F.Range("A2:C" & F.Range("A65536").End(xlUp).Row)
ReDim tablo1(UBound(tablo))
n = 0
'---remplissage des tablo1 et tablo2---
For i = 1 To UBound(tablo)
For j = 2 To 3
v = Val(Replace(tablo(i, j), ",", "."))
If v And (v < 175 Or v > 185) Then
n = n + 1
tablo1(i) = "T" & j - 1 & IIf(v < 175, " - " & 175 - v, " + " & v - 185)
ReDim Preserve tablo2(4, n)
tablo2(1, n) = Trim(tablo(i, 1))
[COLOR="Red"]tablo2(2, n) = IIf(j = 2, tablo(i, 2), "")
tablo2(3, n) = IIf(j = 3, tablo(i, 3), "")[/COLOR]
tablo2(4, n) = tablo1(i)
End If
Next
Next
'---transfert vers les feuilles---
With F.Range("D2:D65536")
.ClearContents
.Resize(UBound(tablo)) = Application.Transpose(tablo1)
End With
With Sheets("Récapitulatif").Range("A65536").End(xlUp)(2).Resize(n, 4)
.Offset(, 4).Resize(1, 1) = F.Name 'indique la feuille en colonne E
.Value = Application.Transpose(tablo2)
.Replace ",", ".", LookAt:=xlPart 'convertit en valeurs numériques (colonnes B et C)
End With
End If
Next
End Sub
Quelle était l'erreur engendrée ?
C'est juste pour essayer de comprendre ton travail.
We use cookies and similar technologies for the following purposes:
Est ce que vous acceptez les cookies et ces technologies?
We use cookies and similar technologies for the following purposes:
Est ce que vous acceptez les cookies et ces technologies?