Tempo fa mi avete suggerito l'utilizzo di questa routine
- Codice: Seleziona tutto
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 6 And Target.Count = 1 Then
Application.EnableEvents = False
If UCase(Target.Value) = "I" Then
If Target.Offset(0, -1) <> "" Then
If Left(Target.Offset(0, -1), 5) = "NOTA INTERNA: " Then
Else
Target.Offset(0, -1) = "NOTA INTERNA: " & Replace(Target.Offset(0, -1), "NOTA ESTERNA: ", "", , , vbTextCompare)
End If
Else
MsgBox "Nessuna nota inserita. Inutile avvalorare il ''Tipo di nota''", vbCritical + vbOKOnly, "Errore"
End If
ElseIf UCase(Target.Value) = "E" Then
If Target.Offset(0, -1) <> "" Then
If Left(Target.Offset(0, -1), 6) = "NOTA ESTERNA" Then
Else
Target.Offset(0, -1) = "NOTA ESTERNA: " & Replace(Target.Offset(0, -1), "NOTA INTERNA: ", "", , , vbTextCompare)
End If
Else
MsgBox "Nessuna nota inserita. Inutile avvalorare il ''Tipo di nota''", vbCritical + vbOKOnly, "Errore"
End If
ElseIf Len(Trim(Target.Value)) = 0 Then
If Len(Trim(Target.Offset(0, -1))) <> 0 Then
If MsgBox("Non avvalorando il tipo di nota, verrà cancellata quella già inserita. Continuare ?", vbQuestion + vbYesNo, "Attenzione") = vbYes Then
Target.Offset(0, -1) = ""
End If
End If
ElseIf UCase(Target.Value) <> "E" And UCase(Target.Value) <> "I" Then
MsgBox "La scelta del tipo di nota inserita è errata. Inserire 'I' o 'E'. ", vbCritical + vbOKOnly, "Errore"
Target.Select
End If
Application.EnableEvents = True
End If
End Sub
che funziona perfettamente.
Ho però un problema. Il foglio in cui opera è composto da circa 20.000 righe.
Ho la necessità, talvolta, di cancellarlo del tutto per poi riscriverlo (da codice vba)
Quando lo seleziono tutto (angolo sinistro) e poi premo il tasto CANC (sia con una macro che da tastiera), viene cancellato il contenuto del foglio, ma poi mi da errore 6 "owerflow" alla prima riga della routine
- Codice: Seleziona tutto
If Target.Column = 6 And Target.Count = 1 Then
Come posso ovviare a questo problema ?
Grazie