Option Explicit
Dim x As Long, col As Byte, DerLiS As Long, DerLiR As Long
Dim li As Long, i As Byte, j As Byte
Dim Total(3) As Double
Dim Cellule As Range
Dim WS As Worksheet
Dim trouve As Boolean
Private Sub UserForm_Initialize()
' Définir le nom de la feuille de RECHERCHE
Set ShtR = Sheets("Recherche")
DerLiR = ShtR.Range("A65536").End(xlUp).Row
ShtR.Range("A2:G" & DerLiR + 2).ClearContents
With ShtR.Range("C2:C" & DerLiR + 2)
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlCenter
End With
End Sub
Private Sub CommandButton1_Click()
Dim VSearch As String
ShtR.[H1].Value = TextBox1.Value
If TextBox1.Value = "" Then Exit Sub
Application.ScreenUpdating = False
x = 1
VSearch = Me.TextBox1.Value
For Each WS In ThisWorkbook.Worksheets
With WS
DerLiS = .Range("D65536").End(xlUp).Row
If Left(.Name, 6) = "Encais" Then
i = Len(TextBox1.Value)
For Each Cellule In .Range("D2:D" & DerLiS)
If InStr(1, Cellule, VSearch, vbTextCompare) > 0 Then
trouve = True
DerLiR = ShtR.Range("A65536").End(xlUp).Row + 1
For col = 1 To 7
ShtR.Cells(DerLiR, col).Value = WS.Cells(Cellule.Row, col + 1).Value
Next
Total(1) = Total(1) + ShtR.Cells(DerLiR, 5).Value
Total(2) = Total(2) + ShtR.Cells(DerLiR, 6).Value
Total(3) = Total(3) + ShtR.Cells(DerLiR, 7).Value
x = x + 1
End If
Next Cellule
End If
End With
Next WS
For col = 5 To 7
ShtR.Cells(DerLiR + 2, col).FormulaLocal = "=SOMME(" & ShtR.Cells(2, col).Address & ":" & ShtR.Cells(DerLiR + 1, col).Address & ")"
Next
With ShtR.Cells(DerLiR + 2, 3)
.Value = "Total "
.HorizontalAlignment = xlRight
.VerticalAlignment = xlCenter
End With
If trouve = False Then MsgBox "Pas de trace !"
Unload Me
Dim madate As String
madate = Format(Date, "dddd dd mmmm yyyy")
With ActiveSheet.PageSetup
.LeftHeader = ""
.CenterHeader = "&""Verdana,Normal""&16Mot-clé : " & TextBox1
.RightHeader = ""
.LeftFooter = "&""Verdana,Normal""Encaissement 2008"
.CenterFooter = _
"&""Verdana,Normal""Edité le & " & madate & "&"" à ,Normal""& &""Verdana,Normal""à&"" à ,Normal"" &T"
.RightFooter = "&""Verdana,Normal""Page &P"
End With
Call Traitement
Application.ScreenUpdating = True
End Sub