Attribute VB_Name = "modUtilitairesIDR1" Option Explicit Public Function SheetExistsIDR(ByVal sheetName As String) As Boolean Dim ws As Worksheet SheetExistsIDR = False For Each ws In ThisWorkbook.Worksheets If UCase(Trim(ws.Name)) = UCase(Trim(sheetName)) Then SheetExistsIDR = True Exit Function End If Next ws End Function Public Function ResetSheetIDR(ByVal sheetName As String) As Worksheet Dim ws As Worksheet Dim lo As ListObject If SheetExistsIDR(sheetName) Then Set ws = ThisWorkbook.Worksheets(sheetName) On Error Resume Next ws.Unprotect If ws.AutoFilterMode Then ws.AutoFilterMode = False End If For Each lo In ws.ListObjects lo.Unlist Next lo ws.Cells.UnMerge ws.Cells.Clear On Error GoTo 0 Else Set ws = ThisWorkbook.Worksheets.Add( _ After:=ThisWorkbook.Worksheets(ThisWorkbook.Worksheets.Count)) ws.Name = sheetName End If Set ResetSheetIDR = ws End Function Public Function GetColumnByHeaderIDR( _ ByVal ws As Worksheet, _ ByVal headerName As String) As Long Dim lastCol As Long Dim c As Long lastCol = ws.Cells(1, ws.Columns.Count).End(xlToLeft).Column For c = 1 To lastCol If UCase(Trim(CStr(ws.Cells(1, c).value))) = _ UCase(Trim(headerName)) Then GetColumnByHeaderIDR = c Exit Function End If Next c GetColumnByHeaderIDR = 0 End Function Public Sub FormatReferentielIDR( _ ByVal ws As Worksheet, _ ByVal headerRange As String) With ws.Range(headerRange) .Font.Bold = True .Interior.Color = RGB(31, 78, 121) .Font.Color = RGB(255, 255, 255) .HorizontalAlignment = xlCenter .VerticalAlignment = xlCenter End With With ws.UsedRange .Borders.LineStyle = xlContinuous .WrapText = True End With ws.Columns.AutoFit ws.Rows(1).RowHeight = 28 End Sub Public Sub AddAnomalieIDR( _ ByVal ws As Worksheet, _ ByVal ongletSource As String, _ ByVal CodeControle As String, _ ByVal codeElement As String, _ ByVal Champ As String, _ ByVal Valeur As String, _ ByVal Gravite As String, _ ByVal Message As String) Dim nextRow As Long nextRow = ws.Cells(ws.Rows.Count, 1).End(xlUp).Row + 1 ws.Cells(nextRow, 1).value = _ "IDR-" & Format(nextRow - 1, "000000") ws.Cells(nextRow, 2).value = Now ws.Cells(nextRow, 3).value = ongletSource ws.Cells(nextRow, 4).value = CodeControle ws.Cells(nextRow, 5).value = codeElement ws.Cells(nextRow, 6).value = Champ ws.Cells(nextRow, 7).value = Valeur ws.Cells(nextRow, 8).value = Gravite ws.Cells(nextRow, 9).value = Message ws.Cells(nextRow, 10).value = "A_TRAITER" End Sub Public Function ToDoubleIDR(ByVal v As Variant) As Double On Error GoTo GestionErreur If IsError(v) Then ToDoubleIDR = 0 ElseIf IsNumeric(v) Then ToDoubleIDR = CDbl(v) Else ToDoubleIDR = 0 End If Exit Function GestionErreur: ToDoubleIDR = 0 End Function Public Function NzIDR( _ ByVal v As Variant, _ Optional ByVal valeurDefaut As Variant = "") As Variant If IsError(v) Then NzIDR = valeurDefaut ElseIf IsNull(v) Then NzIDR = valeurDefaut ElseIf Trim(CStr(v)) = "" Then NzIDR = valeurDefaut Else NzIDR = v End If End Function