Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Const s = "<-- sto per scrivere qui"
Dim u As Long
If Application.Intersect(Target, [pulsantiera]) Is Nothing Then Exit Sub
If Target.Cells.Count > 3 Then Exit Sub
Application.EnableEvents = False
If Target.Cells(1) = "Clean" Then
[pulsantiera].Interior.ColorIndex = -4142 'trasparente
[H1].Select
Application.EnableEvents = True
Exit Sub
End If
If Target.Cells(1) = "Erase table" Then
[pulsantiera].Interior.ColorIndex = -4142 'trasparente
[A:B].ClearContents
[B1] = s
[H1].Select
Application.EnableEvents = True
Exit Sub
End If
[pulsantiera].Interior.ColorIndex = -4142 'trasparente
Target.Interior.ColorIndex = 6 'giallino
'calcolo l'ultima riga valorizzata della colonna A
u = Cells(Cells.Rows.Count, "A").End(xlUp).Row
'se non c'è niente in colonna A, prevedo un tappo
If [COUNTA(A:A)] = 0 Then u = 0
'scrivo nella cella successiva, in riga u+1 della colonna A, il valore del "pulsante" premuto
Cells(u + 1, "A") = Target.Cells(1)
'scrivo nella cella sottostante la frase "Sto per scrivere qui"
'verificando di non aver raggiunto la fine di Excel
If u < Cells.Rows.Count - 2 Then
Cells(u + 1, "B") = ""
Cells(u + 2, "B") = s
End If
[H1].Select
Application.EnableEvents = True
End Sub
|