Ciao https://answers.microsoft.com/it-it/profile/8e3f9463-4f4a-42b5-bc9e-52adf8b87d1cNicolò,
vorrei fare in modo che,fermando il mouse sul valore contenente un valore totale, venisse fuori una specie di POP-UP che ne spiegasse la composizione
Es:
Ricavi 100 (voce totale)
Merce 80 |
Trasporto 15 !---------> voci di dettaglio nella finestra di POP-UP
Incasso Riba 5 |
E' possibile?
Quasi tutto è possibile - la difficoltà risiede spesso nella realizzazione! :-)
Prova qualcosa del genere:
- Fai clic dx sulla linguetta del foglio di interesse
- Seleziona l'opzione Visualizza Codice dal ****
menu contestuale risultante
- Incolla il seguente codice:
'=========>>
Option Explicit
'--------->>
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim Rng As Range, rcell As Range
Dim arrOut() As Variant
Dim sStr As String
Dim iCtr As Long, iLen As Long
If Target.Cells.Count > 1 Then
Exit Sub
End If
sStr = Target.Formula
With Target.Cells(1)
If .HasFormula Then
If InStr(1, sStr, "=Sum", vbTextCompare) > 0 Then
On Error GoTo XIT
Application.EnableEvents = False
Set Rng = .Precedents
End If
Else
Exit Sub
End If
End With
If Not Rng Is Nothing Then
For Each rcell In Rng.Cells
iCtr = iCtr + 1
With rcell
ReDim Preserve arrOut(1 To iCtr)
iLen = Len(.Offset(0, -1).Text)
arrOut(iCtr) = .Offset(0, -1).Value _
& Space(20 - iLen) & .Value
End With
Next rcell
End If
If CBool(iCtr) Then
Call MsgBox( _
Prompt:=Join(arrOut, vbNewLine), _
Buttons:=vbInformation, _
Title:="REPORT")
End If
XIT:
Application.EnableEvents = True
End Sub
'<<=========
- Alt+Q per chiudere l'editor di VBA e tornare a Excel
- Salva il file con l'estensione xlsm
Tuttavia, se questo fosse un requisito significativo, e se fosse per me, vorrei creare una semplice Userform e chiamarla dall`evento Worksheet_SelectionChange. Pertanto, prova qualcosa del genere:
- Fai clic dx sulla linguetta del foglio di interesse
- Seleziona l'opzione Visualizza Codicedal****menu contestuale risultante
- Incolla il seguente codice:
'=========>>
Option Explicit
'--------->>
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim Rng As Range, rcell As Range
Dim arrOut() As Variant
Dim sStr As String
Dim iCtr As Long, iLen As Long
If UserForm1.Visible Then
Unload UserForm1
End If
If Target.Cells.Count > 1 Then
Exit Sub
End If
sStr = Target.Formula
With Target.Cells(1)
If .HasFormula Then
If InStr(1, sStr, "=Sum", vbTextCompare) > 0 Then
On Error GoTo XIT
Application.EnableEvents = False
Set myRng = .Precedents
End If
Else
Exit Sub
End If
End With
If Not myRng Is Nothing Then
UserForm1.Show vbModeless
End If
XIT:
Application.EnableEvents = True
End Sub
'--------->>
Private Sub Worksheet_Deactivate()
If UserForm1.Visible Then
Unload UserForm1
End If
End Sub
'<<=========
- Alt+IM per inserire un nuovo modulo di codice
- Nel nuovo modulo vuoto, incolla il seguente codice:
'=========>>
Option Explicit
Public myRng As Range
- Alt+IUper inserire una nuova Userform
- Sulla Userform insertisci un oggetto ListBox
- F7 per accedere al modulo di codice del
- Nel nuovo modulo vuoto, incolla il seguente codice
'=========>>
Option Explicit
'--------->>
Private Sub UserForm_Activate()
Dim Rng As Range
Dim LBox As MSForms.ListBox
Dim arrIn As Variant
Dim i As Long
Dim UB As Long
Dim iHeight As Long
Set Rng = myRng.Offset(0, -1).Resize(, 2)
arrIn = Rng.Value
UB = UBound(arrIn)
iHeight = UB * 18 - (UB \ 4) * 35
With Me
.Height = iHeight + 20
.Width = 160
.Caption = "Scomposizione"
End With
Set LBox = Me.ListBox1
With LBox
.ColumnCount = 2
.List = arrIn
.Top = 10
.Left = 2
.Height = iHeight
.Width = 150
.BackColor = vbYellow
End With
End Sub
'<<=========
Con questa seconda soluzione, selezionando una cell adi interesse, si vedrebbe qualcosa del genere:

Potresti scaricare il mio file di prova Nicolo20170228.xlsm a:
https://www.dropbox.com/s/4hu1519of163ucy/Nicolo20170228.xlsm?dl=0
In questo file, troverai un esempio della prima soluzione sul Foglio1 e la seconda soluzione sul
Foglio2.
===
Regards,
Norman
