Private Sub CommandButton1_Click()
If interruttore = True Then
MsgBox "SELEZIONARE UN AGENTE"
Exit Sub
End If
Application.ScreenUpdating = False
X = TextBox1.Text
Worksheets("" & X & "").Select
datauno = TextBox2.Text
If datauno = "" Then Exit Sub
datadue = TextBox3.Text
If datadue = "" Then Exit Sub
n = 0
For Each cell In Worksheets("" & X & "").Range("H5:H2000")
If cell.Value >= CDate(datauno) And cell.Value <= CDate(datadue) And cell.Value = "APERTO" Then
a = cell.Offset(0, -7)
b = cell.Offset(0, -6).Value
C = cell.Offset(0, -5).Value
d = cell.Offset(0, 6).Value
e = cell.Offset(0, 9).Value
ListBox1.AddItem a
ListBox1.List(n, 1) = b
ListBox1.List(n, 2) = C
ListBox1.List(n, 3) = d
ListBox1.List(n, 3) = Format$(ListBox1.List(n, 3), "#,###.00")
ListBox1.List(n, 4) = e
ListBox1.List(n, 4) = Format$(ListBox1.List(n, 4), "#,###.00")
n = n + 1
End If
Next
Tot = 0
Tot1 = 0
For n = 0 To ListBox1.ListCount - 1
Tot = Tot + CDbl(ListBox1.List(n, 3))
Tot1 = Tot1 + CDbl(ListBox1.List(n, 4))
Label4.Caption = CDbl(Tot)
Label4 = Format$(Label4, "#,###.00")
Label5.Caption = CDbl(Tot1)
Label5 = Format$(Label5, "#,###.00")
Label17.Caption = CDbl(Label4 - Label5)
Label17 = Format$(Label17, "#,###.00")
Next
M = 0
For Each cell In Worksheets("" & X & "").Range("K5:K20000")
If cell.Value >= CDate(datauno) And cell.Value <= CDate(datadue) Then
f = cell.Offset(0, -10)
g = cell.Offset(0, -9).Value
h = cell.Offset(0, -8).Value
I = cell.Offset(0, 4).Value
l = cell.Offset(0, 8).Value
ListBox2.AddItem f
ListBox2.List(M, 1) = g
ListBox2.List(M, 2) = h
ListBox2.List(M, 3) = I
ListBox2.List(M, 3) = Format$(ListBox2.List(M, 3), "#,###.00")
ListBox2.List(M, 4) = l
ListBox2.List(M, 4) = Format$(ListBox2.List(M, 4), "#,###.00")
M = M + 1
End If
Next
Tot2 = 0
Tot3 = 0
For M = 0 To ListBox2.ListCount - 1
Tot2 = Tot2 + CDbl(ListBox2.List(M, 3))
Tot3 = Tot3 + CDbl(ListBox2.List(M, 4))
Label6.Caption = CDbl(Tot2)
Label6 = Format$(Label6, "#,###.00")
Label7.Caption = CDbl(Tot3)
Label7 = Format$(Label7, "#,###.00")
Label26.Caption = CDbl(Label6 - Label7)
Label26 = Format$(Label26, "#,###.00")
Dim k As Double
Dim j As Double
k = CDbl(Label17.Caption)
j = CDbl(Label26.Caption)
Label28.Caption = k + j
Label28 = Format$(Label28, "#,###.00")
Next
End Sub |