Private Sub CommandButton1_Click()
Application.ScreenUpdating = False
x = ComboBox1
If ComboBox1.Text = "Foglio Base" Or ComboBox1.Text = "" Then
MsgBox "Seleziona L'Agente interessato"
Exit Sub
End If
'sotto: controlliamo con un ciclo For Next che le 4 textbox non siano vuote, altrimenti usciamo avvisando
For I = 1 To 3
If UserForm1.Controls("TextBox" & I).Text = "" Then
MsgBox "MANCANO DATI"
Exit Sub
End If
Next
R = Sheets(x).Range("A" & Rows.Count).End(xlUp).Row + 1
Sheets(x).Cells(R, 1) = TextBox1.Value
Sheets(x).Cells(R, 2) = DTPicker1
Sheets(x).Cells(R, 3) = TextBox2.Value
Sheets(x).Cells(R, 4) = TextBox3.Value
Dim sh As String
sh = ComboBox1
Worksheets(sh).Select
TextBox4 = 1
TextBox5 = 2
TextBox6 = 3
TextBox7 = 4
TextBox8 = 5
Label32.Visible = True
Label34.Visible = True
Label35.Visible = True
Label33.Visible = True
Label36.Visible = True
TextBox10.Visible = True
TextBox11.Visible = True
TextBox12.Visible = True
TextBox13.Visible = True
TextBox14.Visible = True
CommandButton2.Visible = False
Dim myRange, tuoRange As Range
x = TextBox4
Set myRange = Range("C2:C200")
Set tuoRange = Range("A2:A200")
TextBox10 = WorksheetFunction.SumIf(tuoRange, x, myRange)
y = TextBox5
Set myRange = Range("C2:C200")
Set tuoRange = Range("A2:A200")
TextBox11 = WorksheetFunction.SumIf(tuoRange, y, myRange)
R = TextBox6
Set myRange = Range("C2:C200")
Set tuoRange = Range("A2:A200")
TextBox12 = WorksheetFunction.SumIf(tuoRange, R, myRange)
M = TextBox7
Set myRange = Range("C2:C200")
Set tuoRange = Range("A2:A200")
TextBox13 = WorksheetFunction.SumIf(tuoRange, M, myRange)
n = TextBox8
Set myRange = Range("C2:C200")
Set tuoRange = Range("A2:A200")
TextBox14 = WorksheetFunction.SumIf(tuoRange, n, myRange)
Label28.Visible = True
TextBox9.Visible = True
CommandButton5.Visible = True
Dim mr As Range
Set mr = Range("C1:C200")
TextBox9 = WorksheetFunction.Sum(mr)
Application.ScreenUpdating = True
End Sub |