Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

macro associata a cella

1,738 views
Skip to first unread message

mga 297

unread,
Oct 12, 2009, 8:58:01 AM10/12/09
to
esiste la possibilità di associare una macro ad una singola cella
ad esempio se digito in A1 SI eseguo una macro ma se in A1
digito no continuo come se nulla fosse successo???

grazie 1000

marco g

Mauro Gamberini

unread,
Oct 12, 2009, 9:28:16 AM10/12/09
to
> esiste la possibilità di associare una macro ad una singola cella
> ad esempio se digito in A1 SI eseguo una macro ma se in A1
> digito no continuo come se nulla fosse successo???
>

Nel modulo di codice *DEL FOGLIO* dove
hai la cella(qui A1):

Private Sub Worksheet_Change(ByVal Target As Range)
With Target
If UCase(.Value) = "SI" Then
Call tuaMacro
End If
End With
End Sub

In questo caso digitando si o Si o SI o sI nella cella
A1 del foglio, esegui la macro.
Puoi anche definire un Range di celle per i tuoi si:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng As Range
Set rng = Range("A1:A5")
If Not Intersect(Target, rng) Is Nothing Then
With Target
If UCase(.Value) = "SI" Then
Call tuaMacro
End If
End With
End If
Set rng = Nothing
End Sub

Nel caso tu voglia invece eseguire il codice della macro
solo se nella cella trovi si:

Public Sub tuaMacro()
Dim sh As Worksheet
Set sh = Worksheets("Foglio1")
With sh
If UCase(.Range("A1").Value) = "SI" Then
'codice da eseguire
End If
End With
Set sh = Nothing
End Sub

--
---------------------------
Mauro Gamberini
http://www.riolab.org/
http://blog.maurogsc.eu/
http://social.microsoft.com/Forums/it-IT/officeit/threads

r

unread,
Oct 12, 2009, 9:40:02 AM10/12/09
to
"mga 297" ha scritto:

'nel modulo di classe del foglio
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = "$A$1" Then
If Target.Value = "SI" Then
'call tuaMacro
End If
End If
End Sub

saluti
r

--
Come e dove incollare il codice:
http://www.rondebruin.nl/code.htm

Il mio ultimo lavoro ...
http://excelvba.altervista.org/blog/index.php/Excel-VBA/UsedRange-eccezioni-e-alternative.html


r

unread,
Oct 12, 2009, 4:47:01 PM10/12/09
to
ciao Mauro,
sai che quando riesco ... mi piace farti le pulci ... :-)

"Mauro Gamberini" ha scritto:

> > esiste la possibilità di associare una macro ad una singola cella
> > ad esempio se digito in A1 SI eseguo una macro ma se in A1
> > digito no continuo come se nulla fosse successo???
> >
>
> Nel modulo di codice *DEL FOGLIO* dove
> hai la cella(qui A1):
>

a questa ....

> Private Sub Worksheet_Change(ByVal Target As Range)
> With Target
> If UCase(.Value) = "SI" Then
> Call tuaMacro
> End If
> End With
> End Sub

credo manchi qualcosa ...

>
> In questo caso digitando si o Si o SI o sI nella cella
> A1 del foglio, esegui la macro.
> Puoi anche definire un Range di celle per i tuoi si:
>
> Private Sub Worksheet_Change(ByVal Target As Range)
> Dim rng As Range
> Set rng = Range("A1:A5")
> If Not Intersect(Target, rng) Is Nothing Then
> With Target
> If UCase(.Value) = "SI" Then
> Call tuaMacro
> End If
> End With
> End If
> Set rng = Nothing
> End Sub

target potrebbe sempre essere un range di più
celle ... quindi entrambe andrebbero in errore
per es. cancellando due celle nel range a1:a5

>
> Nel caso tu voglia invece eseguire il codice della macro
> solo se nella cella trovi si:
>

questa ...

> Public Sub tuaMacro()
> Dim sh As Worksheet
> Set sh = Worksheets("Foglio1")
> With sh
> If UCase(.Range("A1").Value) = "SI" Then
> 'codice da eseguire
> End If
> End With
> Set sh = Nothing
> End Sub
>

la lascio stare :-)

Mauro Gamberini

unread,
Oct 13, 2009, 3:43:04 AM10/13/09
to
> sai che quando riesco ... mi piace farti le pulci ... :-)
>

LOL!
Mi gratterò...;-)

> target potrebbe sempre essere un range di più
> celle ... quindi entrambe andrebbero in errore
> per es. cancellando due celle nel range a1:a5
>

Vero, dimenticanza(fretta) mia.

With Target
If .Cells.Count = 1 Then


If UCase(.Value) = "SI" Then
Call tuaMacro
End If

End If
End With

r

unread,
Oct 13, 2009, 5:28:01 AM10/13/09
to

"Mauro Gamberini" ha scritto:

> > sai che quando riesco ... mi piace farti le pulci ... :-)
> >
>
> LOL!
> Mi gratterò...;-)

:-)

ciao
r

mga 297

unread,
Oct 13, 2009, 6:40:01 AM10/13/09
to
grazie a tutti e due

proprio quello che volevo

marco g

Mauro Gamberini

unread,
Oct 13, 2009, 7:06:36 AM10/13/09
to
> grazie a tutti e due
>
> proprio quello che volevo
>

Grazie a te per il riscontro.
Se hai problemi, per favore resta
sempre in questo thread. Grazie

--
---------------------------
Mauro Gamberini
http://www.riolab.org/
http://blog.maurogsc.eu/

http://social.microsoft.com/Forums/it-IT/excelit/threads


0 new messages