Ciao Roberto,

Ho un elenco di valori (A2:A7), che possono essere scelti dal controllo ActiveX. La scelta viene riportata in E2 automaticamente. Vorrei che al cambiare del valore in E2 (dalla scelta del controllo ActiveX) si cancelli il valore in G2 e si "costringa" un
utente ad inserire un valore nuovo.
Devo dirti che non mi piacciono troppo i modi di constringere un utente ma, detto questo, forse potresti provare qualcosa del genere:
- Fai clic dx sulla linguetta del foglio
- Seleziona l'opzione Visualizza Codice
- Incolla il seguente codice:
'=========>>
Option Explicit
Private iCtr As Long
Private Const miaCella As String = "G2" '<<==== Modifica
Private blConstringa As Boolean
'--------->>
Private Sub ComboBox1_Change()
Dim Rng As Range
Dim sStr As String
With Me
If .ComboBox1.Value <> vbNullString Then
iCtr = 0
Set Rng = .Range(miaCella)
With Rng
.ClearContents
blConstringa = True
Application.EnableEvents = False
.Select
Application.EnableEvents = True
End With
End If
End With
End Sub
'--------->>
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim Rng As Range
Dim iCtr As Long
If Not blConstringa Then
Exit Sub
End If
Set Rng = Me.Range(miaCella)
iCtr = iCtr + 1
On Error GoTo XIT
Application.EnableEvents = False
If iCtr < 4 Then
If IsEmpty(Rng.Value) Then
Rng.Select
Call MsgBox(Prompt:="Devi inserire un valore nella cella " & miaCella & "!", _
Buttons:=vbCritical, _
Title:="Valore mancante")
Else
blConstringa = False
GoTo XIT
End If
End If
XIT:
If iCtr > 3 And IsEmpty(Rng.Value) Then
Call MsgBox(Prompt:="Allora,sii testardo; fai quello che vuoi tu!!!", _
Buttons:=vbCritical, _
Title:="Valore mancante")
blConstringa = False
End If
Application.EnableEvents = True
End Sub
'<<==========
Alt-Q per chiudere l'editor di VBA e tornare a Excel. Salva il file come un file del tipo xlsm.
===
Regards,
Norman