Vorrei un’analisi di questo listato in lingua italiana, con particolare attenzione ai…
- User
Vorrei un’analisi di questo listato in lingua italiana, con particolare attenzione ai seguenti punti
:- Ridondanza di codice o controlli logici: Identificare eventuali ripetizioni inutili o controlli logici superflui.
- Ottimizzazioni: Suggerire miglioramenti per rendere il codice più efficiente.
- Compattazioni: Proporre modi per rendere il codice più conciso.
- Ricerca di maggiore efficienza e velocità di esecuzione: Consigli su come migliorare le prestazioni del codice. Per ogni punto da 1 a 4, apprezzerei suggerimenti specifici. Option Explicit
Dim wsOdierno As Worksheet Dim wsAnalyze As Worksheet Dim wsData As Worksheet Dim wsStorico As Worksheet
Sub ToggleApplicationSettings(ByVal enable As Boolean) Application.Calculation = IIf(enable, xlCalculationAutomatic, xlCalculationManual) Application.ScreenUpdating = enable Application.EnableEvents = enable End Sub
Sub Analyze_Data() Dim myRanges() As Range
ToggleApplicationSettings False Set wsOdierno = ThisWorkbook.Worksheets("Odierno") Set wsAnalyze = ThisWorkbook.Worksheets("Analyze") Set wsData = ThisWorkbook.Worksheets("Data") Set wsStorico = ThisWorkbook.Worksheets("Storico") CreateRanges myRanges Elabora_Dati myRanges StoricizzaDatieVar ToggleApplicationSettings TrueEnd Sub
Sub CreateRanges(ByRef myRanges() As Range) Dim i As Integer Dim baseRange As String Dim rangesAddresses(1 To 5) As Variant
baseRange = "E12:E49,E51:E62,E64:E81,E84:E96,E98:E111" For i = 1 To 5 rangesAddresses(i) = Split(Replace(baseRange, "E", Chr(69 + i - 1)), ",") Next i ReDim myRanges(1 To 5) ' Usa Join per creare il range senza usare Union For i = 1 To 5 Set myRanges(i) = wsOdierno.Range(Join(rangesAddresses(i), ",")) Next iEnd Sub
Sub Elabora_Dati(ByRef myRanges() As Range) Dim i As Integer
' Riabilita temporaneamente ScreenUpdating per vedere le elaborazioni sul foglio Application.ScreenUpdating = True For i = 2 To 6 wsAnalyze.Select myRanges(i - 1).Copy wsAnalyze.Range("D13") AnalyzeOnly Sheets("VAR").Cells(26, i).Resize(11).Value = Application.Transpose(Sheets("Analyze").Range("F10:P10").Value) Next i ' Disabilita di nuovo ScreenUpdating per migliorare le prestazioni Application.ScreenUpdating = FalseEnd Sub
Sub StoricizzaDatieVar() Dim myMultiAreaPrice As Range Dim wsVAR As Worksheet Dim wsDestinations(1 To 5) As Worksheet Dim col As Integer Dim lastRows As Variant
' Copia dati di sicurezza ed immagazzina dati chiusi precedenti Set wsVAR = ThisWorkbook.Worksheets("VAR") wsVAR.Range("R22:V24").Value = wsVAR.Range("B22:F24").Value ' Incolla su Foglio Data Set myMultiAreaPrice = Union(wsOdierno.Range("A10:A49"), wsOdierno.Range("A51:A62"), wsOdierno.Range("A64:A81"), wsOdierno.Range("A84:A96"), wsOdierno.Range("A98:A111")) myMultiAreaPrice.Copy wsData.Range("A1").End(xlDown).Offset(1, 0).PasteSpecial Paste:=xlValues, Transpose:=True ' Incolla su Foglio Storico wsOdierno.Range("A9:A111").Copy wsStorico.Range("A10").End(xlDown).Offset(1, 0).PasteSpecial Paste:=xlValues, Transpose:=True ' Incolla su altri fogli Set wsDestinations(1) = Sheets("Cass") Set wsDestinations(2) = Sheets("Tr") Set wsDestinations(3) = Sheets("Tot") Set wsDestinations(4) = Sheets("BCC") Set wsDestinations(5) = Sheets("Gen") lastRows = Array(52, 52, 52, 52, 60) ' Colonna 6 ha 60 righe, le altre 52 OrdinaVAR For col = 11 To 15 wsVAR.Range(wsVAR.Cells(3, col), wsVAR.Cells(lastRows(col - 11), col)).Copy wsDestinations(col - 10).Range("A10").End(xlDown).Offset(1, 0).PasteSpecial Paste:=xlValues, Transpose:=True Next col ' Copia dati di sicurezza wsVAR.Range("R61:V68").Value = wsVAR.Range("B61:F68").Value wsVAR.Range("B61:F68").Value = wsVAR.Range("B53:F60").Value Sheets("Gen").Select Application.ScreenUpdating = True - Assistant
- User
Ripetizione nella gestione della configurazione di Application: La funzione ToggleApplicationSettings potrebbe essere utilizzata più efficacemente. Al momento è già usata bene, ma ho notato che ScreenUpdating viene gestito separatamente in Elabora_Dati. Concentrati sull'utilizzo uniforme della funzione per gestire questi stati. Mi mostri dove intervenire sul codice ?
- Assistant