Info completa
hai ragione ...
prima di inserire il codice allora specifico meglio:
il contesto è: una tabella con 5 colonne:
prima: numero della componente (chiamo componenti le sottoparti delle competenze di cui parlavo; questo numero serve ad identificarle)
seconda: descrizione competenza
terza: competenza individuata con bottoni VERO/FALSO
quarta: competenza presente (quindi osservabile) con bottoni VERO/FALSO
quinta: possibile dipendenza della competenza con riferimento al numero di serie della competenza da cui dipende
ogni bottone è nominato nel modo seguente:
"numero competenza" & "Competenza Individuata"/"Competenza Presente"
Grazie ancora
ecco il codice che si attiva cliccando su ognuno di questi pulsanti:
Macro che modifica il valore del pulsante cliccato, della cella sottostante e di vari altri pulsanti e celle ad esso collegati::
Sub VeroFalsoClick()
'
'Al click cambia caption bottone cliccato, valore VERO/FALSO cella sottostante e valori bottoni e celle dipendenti_
' e da cui dipende bottone cliccato
'
Dim Cella As Range
Dim NoRif As Range
Dim RifBott As String
Dim Indicatore As Range
Dim Indicatore2 As Range
Dim Riga As Integer
Dim Colonna As Integer
Dim lunghezza As Integer
Dim lunghezza2 As Integer
Set Indicatore = Range("Tabella2[[#Headers],[Componente Individuata]]")
Set Indicatore2 = Range("Tabella2[[#Headers],[Componente Presente]]")
Set NoRif = Range("Tabella2[[#Headers],[Numero Componente]]")
lunghezza = Len(Indicatore)
lunghezza2 = Len(Indicatore2)
'
'Ricava RIGA cella su cui bottone, in base a nome bottone
'(in nome del bottone è composto da un riferimento numerico alla componente da individuare (Numero Componente)_
'e dal nome della componente individuata: p.e. "2Individua informazioni" ("Numero Compoente" + "Componente Individuata"))
'
Rifer = Application.Caller
If IsNumeric(Left(Rifer, 2)) = True Then 'stabilisce quale parte estrarre da nome bottone
RifBott = Left(Rifer, 2)
Else
RifBott = Left(Rifer, 1)
End If
Set r = ActiveSheet.Cells.Find(RifBott, LookIn:=xlValues, _
After:=Cells(1, 1), _
lookat:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext)
Riga = r.Row
'
'Ricavare COLONNA cella su cui bottone, su base nome bottone
'
InizioRif = Len(RifBott) + 1
If Mid(Rifer, InizioRif, lunghezza) = Indicatore Then 'stabilire quale parte estrarre da nome bottone
RifColonna = Indicatore.Value
Else
RifColonna = Indicatore2.Value
End If
Set c = ActiveSheet.Cells.Find(RifColonna, LookIn:=xlValues, _
After:=Cells(1, 1), _
lookat:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext)
Colonna = c.Column
'
'MODIFICA bottone cliccato e cella sottostante
'
If ActiveSheet.Buttons(Rifer).Caption = "Vero" Then
Set Cella = Cells(Riga, Colonna)
Cella.Value = False
ActiveSheet.Shapes(Rifer).Select
With Selection
.Height = Cella.Height
.Width = Cella.Width
.onAction = "VeroFalsoClick"
.Characters.Text = "Falso"
.Characters.Font.Name = "Calibri"
.Characters.Font.FontStyle = "Normale"
.Characters.Font.Size = 12
.Characters.Font.Strikethrough = False
.Characters.Font.Superscript = False
.Characters.Font.Subscript = False
.Characters.Font.OutlineFont = False
.Characters.Font.Shadow = False
.Characters.Font.Underline = xlUnderlineStyleNone
.Characters.Font.ColorIndex = 3
End With
Else
Set Cella = Cells(Riga, Colonna)
Cella.Value = True
ActiveSheet.Shapes(Rifer).Select
With Selection
.Height = Cella.Height
.Width = Cella.Width
.onAction = "VeroFalsoClick"
.Characters.Text = "Vero"
.Characters.Font.Name = "Calibri"
.Characters.Font.FontStyle = "Normale"
.Characters.Font.Size = 12
.Characters.Font.Strikethrough = False
.Characters.Font.Superscript = False
.Characters.Font.Subscript = False
.Characters.Font.OutlineFont = False
.Characters.Font.Shadow = False
.Characters.Font.Underline = xlUnderlineStyleNone
.Characters.Font.ColorIndex = 5
End With
End If
'
'se "componente presente" FALSO allora anche "componente individuata" FALSO
'
If RifColonna = Indicatore2.Value Then
If Cella.Value = False Then
Cella.Offset(0, -1).Value = False
bottoneaccanto = RifBott & Indicatore
ActiveSheet.Shapes(bottoneaccanto).Select
With Selection
.Height = Cella.Offset(0, -1).Height
.Width = Cella.Offset(0, -1).Width
.onAction = "VeroFalsoClick"
.Characters.Text = "Falso"
.Characters.Font.Name = "Calibri"
.Characters.Font.FontStyle = "Normale"
.Characters.Font.Size = 12
.Characters.Font.Strikethrough = False
.Characters.Font.Superscript = False
.Characters.Font.Subscript = False
.Characters.Font.OutlineFont = False
.Characters.Font.Shadow = False
.Characters.Font.Underline = xlUnderlineStyleNone
.Characters.Font.ColorIndex = 3
End With
End If
End If
'
'se "componente individuata" VERO allora anche "componente presente" VERO
'
If RifColonna = Indicatore.Value Then
If Cella.Value = True Then
bottoneaccanto = RifBott & Indicatore2
Cella.Offset(0, 1) = True
ActiveSheet.Shapes(bottoneaccanto).Select
With Selection
.Height = Cella.Offset(0, 1).Height
.Width = Cella.Offset(0, 1).Width
.onAction = "VeroFalsoClick"
.Characters.Text = "Vero"
.Characters.Font.Name = "Calibri"
.Characters.Font.FontStyle = "Normale"
.Characters.Font.Size = 12
.Characters.Font.Strikethrough = False
.Characters.Font.Superscript = False
.Characters.Font.Subscript = False
.Characters.Font.OutlineFont = False
.Characters.Font.Shadow = False
.Characters.Font.Underline = xlUnderlineStyleNone
.Characters.Font.ColorIndex = 5
End With
'
'se "componente individuata" VERO e presente dipendenza specificata in altra cella accanto_
'allora "componente individuata" da cui dipende VERO
' QUI è il mio problema, perché vorrei attivare questi pulsanti e non cambiarne il valore.
' attivandoli innescherei il loro .onAction, cambiandone il valore invece non si innesca
'
If Cella.Offset(0, 2) <> "" Then
bottonesopra = Cella.Offset(0, 2).Value & Indicatore
Set s = ActiveSheet.Cells.Find(Cella.Offset(0, 2).Value, LookIn:=xlValues, _
After:=Cells(1, 1), _
lookat:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext)
liv = s.Row
Cells(liv, Colonna).Value = True
ActiveSheet.Shapes(bottonesopra).Select
With Selection
.Height = Cells(liv, Colonna).Height
.Width = Cells(liv, Colonna).Width
.onAction = "VeroFalsoClick"
.Characters.Text = "Vero"
.Characters.Font.Name = "Calibri"
.Characters.Font.FontStyle = "Normale"
.Characters.Font.Size = 12
.Characters.Font.Strikethrough = False
.Characters.Font.Superscript = False
.Characters.Font.Subscript = False
.Characters.Font.OutlineFont = False
.Characters.Font.Shadow = False
.Characters.Font.Underline = xlUnderlineStyleNone
.Characters.Font.ColorIndex = 5
End With
End If
End If
End If
End Sub