
Sub commento()
Set sh1 = Workbooks("CC.xlsm").Worksheets("rendimento")
Dim aCell As Range
Set aCell = sh1.Range("B41")
n = WorksheetFunction.Clean(aCell.Comment.Text)
sh1.Range("Z100").Value = n
End Sub |
Option Explicit
Sub Tabbbbbella()
Dim oCmt As Comment
Dim oTbl As ListObject
Dim ws As Worksheet
Dim strCmt As String
Dim Cella As Range
Set ws = ActiveSheet
With ws
Set oTbl = .ListObjects("Tabella1")
For Each Cella In oTbl.Range
Set oCmt = Cella.Comment
If Not oCmt Is Nothing Then
strCmt = oCmt.Text
Debug.Print strCmt; oCmt.Parent.Address
End If
Set oCmt = Nothing
Next Cella
Set oTbl = Nothing
End With
Set ws = Nothing
End Sub |
Option Explicit
Sub Tabbbbbella()
Dim oCmt As Comment 'variabile oggetto di tipo commento
Dim oTbl As ListObject 'variabile oggetto di tipo tabella
Dim ws As Worksheet 'variabile oggetto di tipo "foglio di lavoro"
Dim strCmt As String 'variabile di tipo stringa
Dim Cella As Range 'variabile di tipo range
Set ws = ActiveSheet 'mera abitudine, istanzio oggetto ws il foglio attivo
With ws
Set oTbl = .ListObjects("Tabella1") 'poco duttile, ma con 1 tabella con quel nome istanzio la variabile sulla tabella
For Each Cella In oTbl.Range 'per ogni cella nel range della tabella
Set oCmt = Cella.Comment 'istanzio la variabile oCmt come il commento della cella
If Not oCmt Is Nothing Then 'se non è nulla, cioè se esiste il commento per quella cella
strCmt = oCmt.Text 'la variabile stringa diventa il testo del commento
Debug.Print strCmt; oCmt.Parent.Address
End If
Set oCmt = Nothing 'distruggo variabile oggetto
Next Cella
Set oTbl = Nothing 'distruggo
End With
Set ws = Nothing 'distruggo
End Sub
|
'codice 1
Sub commento()
Dim aCell As Range
Dim n As String
Dim oCmt As Comment
Set sh1 = Workbooks("CC.xlsm").Worksheets("rendimento")
Set aCell = sh1.Range("B41")
Set oCmt = aCell.Comment
n = oCmt.Text
sh1.Range("Z100").Value = n
End Sub
'codice 2
Sub commento()
Dim oTbl As ListObject
Dim aCell As Range
Dim n As String
Dim oCmt As Comment
Set oTbl = Worksheets("rendimento").ListObjects("Tabella1")
Set sh1 = Workbooks("CC.xlsm").Worksheets("rendimento")
Set aCell = sh1.Range("B41")
Set oCmt = aCell.Comment
n = oCmt.Text
sh1.Range("Z100").Value = n
End Sub |
Option Explicit
Sub commento()
Dim oTbl As ListObject
Dim rCell As Range
Dim n As String
Dim oCmt As Comment
Dim sh1 As Worksheet
Set sh1 = Workbooks("CC.xlsm").Worksheets("rendimento")
For Each oTbl In sh1.ListObjects 'CERCA IN TUTTE LE TABELLE DEL FOGLIO
If oTbl.Range(1, 1) = "ILVALOREDELLAPRIMrCellADELLATABELLA" Then 'CERCHI UN DETERMINATO VALORE
'If oTbl.Name = "Tabella3" Then 'ALTERNATIVA SAPENDO IL NOME DELLA TABELLA
Set oTbl = oTbl 'SE LA TROVO ISTANZIO LA TABELLA
Exit For 'ESCO DAL CICLO
End If
Next oTbl
If Not oTbl Is Nothing Then 'SE HO TROVATO LA TABELLA
For Each rCell In oTbl.Range 'CERCO IN TUTTE LE SUE CELLE
Set oCmt = rCell.Comment 'ISTANZIO COMMENTO
If Not oCmt Is Nothing Then 'SE ESISTE IL COMMENTO
n = oCmt.Text 'VALORIZZO VARIABILE
Debug.Print n 'QUI USALO COME TI SERVE
End If
Set oCmt = Nothing 'DISTURGGO COMMENTO O ME LO TRASCINO AL CICLO SUCCESSIVO
Next rCell
End If
'sh1.Range("Z100").Value = n
Set sh1 = Nothing
End Sub
|
Option Explicit
Sub trova_nome_tabella()
Dim oTbl As ListObject
Dim rCell As Range
Dim n As String
Dim oCmt As Comment
Dim sh1 As Worksheet
Set sh1 = Workbooks("CC.xlsm").Worksheets("rendimento")
For Each oTbl In sh1.ListObjects 'CERCA IN TUTTE LE TABELLE DEL FOGLIO
If oTbl.Range(1, 11) = "plus/minus spesa" Then 'CERCHI UN DETERMINATO VALORE
n = oTbl.Name
Exit For 'ESCO DAL CICLO
End If
Next oTbl
sh1.Range("Z100").Value = n
End Sub
|
Sub flussi_di_cassa()
Dim oTbl As ListObject
Dim oCmt1 As Comment
Dim oCmt2 As Comment
Dim oneRange As Range
Dim aCell As Range
Dim n As String
Set sh1 = Workbooks("CC.xlsm").Worksheets("rendimento")
Set sh2 = Workbooks("CC.xlsm").Worksheets("flussi di cassa--cedole")
Set SourceRange = sh2.Range("K19")
Set oTbl = Worksheets("rendimento").ListObjects("Tabella11")
'definisco il range delle date
UltimaRigafoglio1 = sh1.Range("D65536").End(xlUp).Row
Set oneRange = sh1.Range("D28:D" & UltimaRigafoglio1)
Set aCell = sh1.Range("D28")
'seleziono il mese attuale
mese = Month(sh1.Range("B4"))
'seleziono la prima cella in cui deve copiare delle date (anche questo deve essere variabile)
Sheets("flussi di cassa--cedole").Activate
sh2.Range("K19").Select
For Each aCell In oneRange
Set oCmt1 = aCell.Comment
Set oCmt2 = aCell.Offset(0, 2).Comment 'tassazione
'n = WorksheetFunction.Clean(aCell.Comment.Text) 'numero di cedole: funziona solo se la cella non fa parte di una tabella
Set n = oCmt1.Text
'n = 1
attivo = aCell.Offset(0, 1).Value 'bond attivo o no
If (attivo = "si") Then
If (n = 1) Then
'grandezze di interesse
anno = IIf(Month(aCell) > mese, 2013, 2014)
nuovadata = DateSerial(anno, Month(aCell), Day(aCell))
A = aCell.Offset(0, -3).Value
B = aCell.Offset(0, 2).Value
ActiveCell.Value = nuovadata
ActiveCell.Offset(0, 1).Select
ActiveCell.Formula = (A * B)
ActiveCell.Offset(0, 1).Value = aCell.Offset(0, 6).Value
ActiveCell.Offset(1, -1).Select
ElseIf (n = 2) Then
'dichiaro le variabili di interesse
anno = IIf(Month(aCell) > mese, 2013, 2014)
nuovadata = DateSerial(anno, Month(aCell), Day(aCell))
oggi = Date
nuovo_mese = Month(aCell) - 6
altro_flusso = DateSerial(anno, nuovo_mese, Day(aCell))
'calcolo la data dell'altro flusso
If (altro_flusso < oggi) Then
nuovo_mese = Month(aCell) + 6
altro_flusso = DateSerial(anno, nuovo_mese, Day(aCell))
End If
A = aCell.Offset(0, -3).Value
B = aCell.Offset(0, 2).Value
ActiveCell.Value = nuovadata
ActiveCell.Offset(0, 1).Select
ActiveCell.Formula = (A * B) / n
ActiveCell.Offset(0, 1).Value = aCell.Offset(0, 6).Value
ActiveCell.Offset(1, -1).Select
ActiveCell.Value = altro_flusso
ActiveCell.Offset(0, 1).Select
ActiveCell.Formula = (A * B) / n
ActiveCell.Offset(0, 1).Value = aCell.Offset(0, 6).Value
ActiveCell.Offset(1, -1).Select
ElseIf (n = 3) Then
anno = IIf(Month(aCell) > mese, 2013, 2014)
nuovadata = DateSerial(anno, Month(aCell), Day(aCell))
oggi = Date
mese1 = Month(aCell) - 4
flusso1 = DateSerial(anno, mese1, Day(aCell))
mese2 = Month(aCell) - 8
flusso2 = DateSerial(anno, mese2, Day(aCell))
If flusso1 < oggi And flusso2 < oggi Then
mese1 = Month(aCell) + 4
flusso1 = DateSerial(anno, mese1, Day(aCell))
mese2 = Month(aCell) + 8
flusso2 = DateSerial(anno, mese2, Day(aCell))
ElseIf flusso1 > oggi And flusso2 < oggi Then
mese2 = mese1 + 8
flusso2 = DateSerial(anno, mese2, Day(aCell))
End If
A = aCell.Offset(0, -3).Value
B = aCell.Offset(0, 2).Value
ActiveCell.Value = nuovadata
ActiveCell.Offset(0, 1).Select
ActiveCell.Formula = (A * B) / n
ActiveCell.Offset(0, 1).Value = aCell.Offset(0, 6).Value
ActiveCell.Offset(1, -1).Select
ActiveCell.Value = flusso1
ActiveCell.Offset(0, 1).Select
ActiveCell.Formula = (A * B) / n
ActiveCell.Offset(0, 1).Value = aCell.Offset(0, 6).Value
ActiveCell.Offset(1, -1).Select
ActiveCell.Value = flusso2
ActiveCell.Offset(0, 1).Select
ActiveCell.Formula = (A * B) / n
ActiveCell.Offset(0, 1).Value = aCell.Offset(0, 6).Value
ActiveCell.Offset(1, -1).Select
ElseIf (n = 4) Then
'grandezze di interesse. Qua vanno ricavati 4 flussi
anno = IIf(Month(aCell) > mese, 2013, 2014)
nuovadata = DateSerial(anno, Month(aCell), Day(aCell))
oggi = Date
mese1 = Month(aCell) - 3
flusso1 = DateSerial(anno, mese1, Day(aCell))
mese2 = Month(aCell) - 6
flusso2 = DateSerial(anno, mese2, Day(aCell))
mese3 = Month(aCell) - 9
flusso3 = DateSerial(anno, mese3, Day(aCell))
If flusso1 < oggi And flusso2 < oggi And flusso3 < oggi Then
mese1 = Month(aCell) + 3
flusso1 = DateSerial(anno, mese1, Day(aCell))
mese2 = Month(aCell) + 6
flusso2 = DateSerial(anno, mese2, Day(aCell))
mese3 = Month(aCell) + 9
flusso3 = DateSerial(anno, mese3, Day(aCell))
ElseIf flusso1 > oggi And flusso2 < oggi And flusso3 < oggi Then
mese2 = mese1 + 6
flusso2 = DateSerial(anno, mese2, Day(aCell))
mese3 = mese1 + 9
flusso3 = DateSerial(anno, mese3, Day(aCell))
ElseIf flusso1 > oggi And flusso2 > oggi And flusso3 < oggi Then
mese3 = mese1 + 6
flusso3 = DateSerial(anno, mese3, Day(aCell))
End If
A = aCell.Offset(0, -3).Value
B = aCell.Offset(0, 2).Value
ActiveCell.Value = nuovadata
ActiveCell.Offset(0, 1).Select
ActiveCell.Formula = (A * B) / n
ActiveCell.Offset(0, 1).Value = aCell.Offset(0, 6).Value
ActiveCell.Offset(1, -1).Select
ActiveCell.Value = flusso1
ActiveCell.Offset(0, 1).Select
ActiveCell.Formula = (A * B) / n
ActiveCell.Offset(0, 1).Value = aCell.Offset(0, 6).Value
ActiveCell.Offset(1, -1).Select
ActiveCell.Value = flusso2
ActiveCell.Offset(0, 1).Select
ActiveCell.Formula = (A * B) / n
ActiveCell.Offset(0, 1).Value = aCell.Offset(0, 6).Value
ActiveCell.Offset(1, -1).Select
ActiveCell.Value = flusso3
ActiveCell.Offset(0, 1).Select
ActiveCell.Formula = (A * B) / n
ActiveCell.Offset(0, 1).Value = aCell.Offset(0, 6).Value
ActiveCell.Offset(1, -1).Select
End If
End If
Next
'ordinamento
Uriga = sh2.Cells(Rows.Count, 11).End(xlUp).Row
sh2.Range("K19:M" & Uriga).Sort Key1:=Range("K19:K" & Uriga), Order1:=xlAscending, DataOption1:=xlSortNormal
End Sub
|
Sub flussi_di_cassa_ridotto()
Dim oTbl As ListObject
Dim oCmt1 As Comment
Dim oCmt2 As Comment
Dim oneRange As Range
Dim aCell As Range
'Dim n As String
'come ottengo la prima riga vuota partendo dall'alto?
Set sh1 = Workbooks("CC.xlsm").Worksheets("rendimento")
Set sh2 = Workbooks("CC.xlsm").Worksheets("flussi di cassa--cedole")
Set SourceRange = sh2.Range("K19")
Set oTbl = Worksheets("rendimento").ListObjects("Tabella11")
'definisco il range delle date
UltimaRigafoglio1 = sh1.Range("D65536").End(xlUp).Row
Set oneRange = sh1.Range("D31:D" & UltimaRigafoglio1)
Set aCell = sh1.Range("D31")
'seleziono il mese attuale
mese = Month(sh1.Range("B4"))
'seleziono la prima cella in cui deve copiare delle date (anche questo deve essere variabile)
Sheets("flussi di cassa--cedole").Activate
sh2.Range("K19").Select
For Each aCell In oneRange
Set oCmt1 = aCell.Comment
n = oCmt1.Text
If (n = 1) Then
ActiveCell.Value = n
ActiveCell.Offset(1, 0).Select
ElseIf (n = 2) Then
ActiveCell.Value = n
ActiveCell.Offset(1, 0).Select
End If
Next
End Sub
|
