Private Sub Worksheet_Change(ByVal Target As Range) If Intersect(Target, Range("F1")) Is Nothing Then Exit Sub On Error Resume Next Dim i As Long Dim C_volte As Long C_volte = 0 Dim SH1 As String SH1 = "Foglio1" For i = 2 To Sheets(SH1).Cells(Rows.Count, "A").End(xlUp).Row If Sheets(SH1).Cells(i, "A") <> Range("F1") Then If Sheets(SH1).Cells(i, "B") = Range("F3") And Sheets(SH1).Cells(i, "C") = Range("F2") Then C_volte = C_volte + 1 End If Else C_volte = C_volte + 1 Exit For End If Next i Range("H2") = C_volte '' mettere il Range a B2 End Sub |
Private Sub Worksheet_Change(ByVal Target As Range) If Intersect(Target, Range("F1")) Is Nothing Then Exit Sub On Error Resume Next Dim i As Long, Nriga As Long Dim C_volte As Long C_volte = 0 Dim SH1 As String SH1 = "Foglio1" Dim Cliente As String, Citta As String For i = 2 To Sheets(SH1).Cells(Rows.Count, "A").End(xlUp).Row If Sheets(SH1).Cells(i, "A") = Range("F1") Then Nriga = i Cliente = Sheets(SH1).Cells(i, "C") Citta = Sheets(SH1).Cells(i, "B") End If Next i For i = 2 To Nriga If Sheets(SH1).Cells(i, "C") = Cliente And Sheets(SH1).Cells(i, "B") = Citta Then C_volte = C_volte + 1 End If Next i Range("B2") = C_volte Range("F2") = Cliente Range("F3") = Citta Range("B3") = "SI" If C_volte > 3 Then Range("B3") = "NO" End Sub |
Private Sub Worksheet_Change(ByVal Target As Range) Sheets("Gastos").Unprotect Password:="123" If Not Intersect(Target, Range("F1")) Is Nothing Then On Error Resume Next Select Case Len(Target.Value) Case Is = 1 Target.Value = Year(Date) & "0000" & Target.Value Case Is = 2 Target.Value = Year(Date) & "000" & Target.Value Case Is = 3 Target.Value = Year(Date) & "00" & Target.Value Case Is = 4 Target.Value = Year(Date) & "0" & Target.Value Case Is = 5 Target.Value = Year(Date) & "" & Target.Value End Select End If If Intersect(Target, Range("F1")) Is Nothing Then Exit Sub On Error Resume Next Dim i As Long, Nriga As Long Dim C_volte As Long C_volte = 0 Dim SH1 As String SH1 = "Escalas" Dim Barco As String, Puerto As String For i = 2 To Sheets(SH1).Cells(Rows.Count, "A").End(xlUp).Row If Sheets(SH1).Cells(i, "A") = Range("F1") Then Nriga = i Barco = Sheets(SH1).Cells(i, "C") Puerto = Sheets(SH1).Cells(i, "B") End If Next i For i = 2 To Nriga If Sheets(SH1).Cells(i, "C") = Barco And Sheets(SH1).Cells(i, "B") = Puerto Then C_volte = C_volte + 1 End If Next i Range("C62") = "SI" If C_volte > 3 Then Range("C62") = "NO" Sheets("Gastos").Protect Password:="123" End Sub |
Option Explicit Private Sub Worksheet_Change(ByVal Target As Range) If Intersect(Target, Range("F1")) Is Nothing Then Exit Sub ''controllo scrittura F1 non protetta On Error Resume Next ''''''''''''''' indicizzazione delle variabili ''''''''''''' Dim i As Long, Nriga As Long Dim C_volte As Long C_volte = 0 Dim SH1 As String SH1 = "Escalas" Dim Barco As String, Puerto As String ''''''''''''''''''Inizia il Lavoro '''''''''''''''''''' Sheets("Gastos").Unprotect Password:="123" ''Toglie protezione foglio Select Case Len(Target.Value) ''Controllo immissione in F1 Case Is = 1 Target.Value = Year(Date) & "0000" & Target.Value Case Is = 2 Target.Value = Year(Date) & "000" & Target.Value Case Is = 3 Target.Value = Year(Date) & "00" & Target.Value Case Is = 4 Target.Value = Year(Date) & "0" & Target.Value Case Is = 5 Target.Value = Year(Date) & "" & Target.Value End Select '' Fine controllo '' ricerca dei dati per il calcolo For i = 2 To Sheets(SH1).Cells(Rows.Count, "A").End(xlUp).Row If Sheets(SH1).Cells(i, "A") = Range("F1") Then Nriga = i Barco = Sheets(SH1).Cells(i, "C") Puerto = Sheets(SH1).Cells(i, "B") End If Next i For i = 2 To Nriga If Sheets(SH1).Cells(i, "C") = Barco And Sheets(SH1).Cells(i, "B") = Puerto Then C_volte = C_volte + 1 End If Next i Range("C62") = "SI" If C_volte > 3 Then Range("C62") = "NO" ''''''' fine lavoro Sheets("Gastos").Protect Password:="123" ''attivazione della pass nel foglio End Sub |