1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| Sub OfficeToTool()
Dim Recherch As Range
Dim x As Byte, C As Byte
Dim Ws1 As Workbook, Ws2 As Workbook
toolOpen
Set Ws1 = Workbooks("book1.xls")
Set Ws2 = Workbooks("book2.xls")
For C = 15 To 23
With Ws1.Worksheets("sheet1")
Set Recherch = .Cells(C, 2)
x = Application.CountIf(.Range("B15:B23"), Recherch.Value)
End With
With Ws2.Worksheets("sheet1")
If Recherch.Value = 3 Then
.Range("C14").Value = x
ElseIf Recherch.Value = 5 Then
.Range("C15").Value = x
ElseIf Recherch.Value = 7 Then
.Range("C16").Value = x
ElseIf Recherch.Value = 10 Then
.Range("C17").Value = x
ElseIf Recherch.Value = 15 Then
.Range("C18").Value = x
ElseIf Recherch.Value = 20 Then
.Range("C19").Value = x
ElseIf Recherch.Value = 25 Then
.Range("C20").Value = x
ElseIf Recherch.Value = 30 Then
.Range("C21").Value = x
End If
End With
Next C
Ws2.Worksheets("sheet1").Range("B32").Copy
Ws1.Worksheets("sheet1").Range("C34").PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
Set Recherch = Nothing
Set Ws1 = Nothing
Set Ws2 = Nothing
End Sub
Sub toolOpen()
On Error Resume Next
Workbooks("book2.xls").Activate
If Err <> 0 Then
Workbooks.Open ("C:\users\entreprise\desktop\book2.xls")
On Error GoTo 0
End If
End Sub |
Partager