
Sub Macro1()
'
' Macro1 Macro
'
Dim LastRow, I, Index As Long
'create a copy of Banca
Sheets("Banca 2015").Select
Application.DisplayAlerts = False
Sheets("Banca 2015").Copy Before:=Sheets(3)
Application.DisplayAlerts = True
Index = 3
' clear all rows except 1 and 2
With Worksheets("Banca 2015 (2)")
Rows("3:" & .Rows.Count).Delete
End With
Sheets("Prima nota 2015").Activate
LastRow = Range("A" & Rows.Count).End(xlUp).Row
For I = 3 To LastRow
If CSng(Cells(I, 1)) < CSng("00101") Then
Worksheets("Banca 2015 (2)").Cells(Index, 1) = Cells(I, 1)
Range("B" & I).Select
Selection.Copy
Sheets("Banca 2015 (2)").Activate
Range("B" & Index).Select
Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Sheets("Prima nota 2015").Activate
Worksheets("Banca 2015 (2)").Cells(Index, 3) = Cells(I, 3)
If CSng(Cells(I, 1)) = CSng("00025") Then
Worksheets("Banca 2015 (2)").Cells(Index, 4) = Cells(I, 5)
Else
Worksheets("Banca 2015 (2)").Cells(Index, 5) = Cells(I, 4)
End If
Worksheets("Banca 2015 (2)").Cells(Index, 6) = Cells(I, 6)
Sheets("Banca 2015 (2)").Select
Sheets("Banca 2015 (2)").Range("G2:L2").Select
Selection.Copy
Worksheets("Banca 2015 (2)").Cells(Index, 7).Select
Worksheets("Banca 2015 (2)").Paste
Sheets("Prima nota 2015").Select
' se codice 00025 POS aggiungere una riga di commissioni POS
' (codice 0002) come USCITE
If CSng(Cells(I, 1)) = CSng("00025") Then
Index = Index + 1
Worksheets("Banca 2015 (2)").Cells(Index, 1) = "00026"
Range("B" & I).Select
Selection.Copy
Sheets("Banca 2015 (2)").Activate
Range("B" & Index).Select
Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Sheets("Prima nota 2015").Activate
Worksheets("Banca 2015 (2)").Cells(Index, 3) = Cells(I, 3)
Worksheets("Banca 2015 (2)").Cells(Index, 5) = Cells(I, 5) * 0.7 / 100
Worksheets("Banca 2015 (2)").Cells(Index, 6) = "Commissione Bancomat"
Sheets("Banca 2015 (2)").Select
Sheets("Banca 2015 (2)").Range("G2:L2").Select
Selection.Copy
Worksheets("Banca 2015 (2)").Cells(Index, 7).Select
Worksheets("Banca 2015 (2)").Paste
End If
Sheets("Prima nota 2015").Select
Index = Index + 1
End If
Next I
' delete old sheet and rename new one
Application.DisplayAlerts = False
Sheets("Banca 2015").Delete
Application.DisplayAlerts = True
Sheets("Banca 2015 (2)").Name = "Banca 2015"
End Sub
|
Option Explicit
Sub test()
' prendo il foglio1 e lo rinomino quindi lo ricopio e ne ottengo un doppione
' se apro la finestra progetti (Alt-F11 e Ctrl-R) noto la differenza tra nome esterno e nome interno
Sheets("Foglio1").Name = "Banca 2015"
Sheets("Banca 2015").Copy after:=Sheets("Banca 2015")
End Sub
Sub test2()
' rinomino il foglio1 e lo copio creando un duplicato
' i codename interni sono diversi (per quello che era il foglio1 però rimane foglio1)
Sheets("Foglio1").Name = "Banca 2015"
Sheets("Banca 2015").Copy after:=Sheets("Banca 2015")
' elimino l'originale foglio1 che avevo rinominato... ne elimino anche il codename originale che era sempre foglio1
Application.DisplayAlerts = False
Sheets("Banca 2015").Delete
'rinomino il doppione chiamandolo col nome del "padre"... ma il suo codename rimane intatto e NON è foglio1 (che è sparito)
Sheets("Banca 2015 (2)").Name = "Banca 2015"
' ora con uno sporco trucco riassegno il codename foglio1, che era l'originale, al foglio figlio rinominato
ThisWorkbook.VBProject.VBComponents(Sheets("Banca 2015").CodeName).Properties("_CodeName") = "Foglio1"
Application.DisplayAlerts = True
' purtroppo questo trucco non conserva i riferimenti al foglio precedentemente impostati nelle formule
' le celle che contenevano riferimenti al vecchio foglio1 eliminato, ricevono l'errore RIF
End Sub |
Sub Macro1()
'
' Macro1 Macro
'
Dim LastRow, I, Index As Long
Dim ActualCodename, ActualCodename2 As String
'create a copy of Banca
Sheets("Banca 2015").Select
' get the codename for "Banca 2015" to be used later...
ActualCodename = Sheets("Banca 2015").CodeName
Application.DisplayAlerts = False
Sheets("Banca 2015").Copy Before:=Sheets(3)
Application.DisplayAlerts = True
Index = 3
'working code follows
'.........................................
' delete old sheet and rename new one
Application.DisplayAlerts = False
Sheets("Banca 2015").Delete
Application.DisplayAlerts = True
' rename new worksheet... (external name)
Sheets("Banca 2015 (2)").Name = "Banca 2015"
'get codename of this new worksheet...
ActualCodename2 = Sheets("Banca 2015 (2)").CodeName
' restore original codename...
With ActiveWorkbook
.VBProject.VBComponents(ActualCodename2).Properties("_CodeName").Value = ActualCodename
End With
End Sub
|
Sub Macro1()
'
' Macro1 Macro
'
Dim LastRow, I, Index As Long
Dim ActualCodename, ActualCodename2 As String
'create a copy of Banca
Sheets("Banca 2015").Select
' get the codename for "Banca 2015" to be used later
ActualCodename = Sheets("Banca 2015").CodeName
Application.DisplayAlerts = False
Sheets("Banca 2015").Copy Before:=Sheets(3)
Application.DisplayAlerts = True
' working code follows...
'***************************************+
' delete old sheet and rename new one
Application.DisplayAlerts = False
Sheets("Banca 2015").Delete
Application.DisplayAlerts = True
'Rename sheet (EXTERNAL name)
Sheets("Banca 2015 (2)").Name = "Banca 2015"
'get codename of this renamed sheet
ActualCodename2 = Sheets("Banca 2015").CodeName
' restore original codename saved at the beginning...
With ActiveWorkbook
.VBProject.VBComponents(ActualCodename2).Properties("_CodeName").Value = ActualCodename
End With
End Sub
|
