Una famiglia di software per fogli di calcolo Microsoft con strumenti per l'analisi, la creazione di grafici e la comunicazione dei dati.
Ciao Daniel,
Buongiorno, scrivo qui perché ho un problema piuttosto rognoso.
In poche parole ho un file excel pieno di dati fino alla riga 5146 e la colonna 131 però ho tutto le celle del foglio generate (fino alla riga 1048576 e la colonna 16384), quindi mi ritrovo un file ingestibile, ogni 3x2 excel va in crash e bisogna aspettare parecchio per fare qualsiasi modifica o applicare un qualsiasi filtro.
Quindi vorrei sapere se c'è un modo per alleggerire il file senza compromettere i dati che ci sono dentro visto che è un file condiviso pieno di macro.
Il file in totale pesa 9,02mb.
Prova:
- Alt+F11 per aprire l'editor di VBA
- Alt+IM per inserire un nuovo modulo di codice
- Nel nuovo modulo vuoto, incolla il seguente codice:
'=========>>
Option Explicit
'--------->>
Public Sub Tester()
Dim WB As Workbook
Dim LRow As Long, LCol As Long
Dim SH As Worksheet
Dim Rng As Range
Const sNome_File As String = "Pippo.xlsm" '<<=== Modifica
Set WB = Workbooks(sNome_File)
For Each SH In WB.Worksheets
With SH
LRow = 0
LCol = 0
Set Rng = .UsedRange
On Error Resume Next
LRow = LastRow(SH)
LCol = LastCol(SH)
On Error GoTo 0
If LRow * LCol = 0 Then
.Columns.Delete
Else
.Range(.Cells(LRow + 1, 1), _
.Cells(.Rows.Count, 1)).EntireRow.Delete
.Range(.Cells(1, LCol + 1), _
.Cells(1, .Columns.Count)).EntireColumn.Delete
End If
End With
Next SH
End Sub
'--------->>
Public Function LastRow(SH As Worksheet, _
Optional Rng As Range, _
Optional minRow As Long = 1, _
Optional sPassword As String)
Dim bProtected As Boolean
With SH
If Rng Is Nothing Then
Set Rng = .Cells
End If
bProtected = .ProtectContents = True
If bProtected Then
Application.ScreenUpdating = False
.Unprotect Password:=sPassword
End If
End With
On Error Resume Next
LastRow = Rng.Find(What:="*", _
after:=Rng.Cells(1), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
On Error GoTo 0
If LastRow < minRow Then
LastRow = minRow
End If
If bProtected Then
SH.Protect Password:=sPassword, _
UserInterfaceOnly:=True
End If
Application.ScreenUpdating = True
End Function
'--------->>
Public Function LastCol(SH As Worksheet, _
Optional Rng As Range, _
Optional sPassword As String)
Dim bProtected As Boolean
With SH
If Rng Is Nothing Then
Set Rng = .Cells
End If
bProtected = .ProtectContents = True
If bProtected Then
.Unprotect Password:=sPassword
End If
End With
On Error Resume Next
LastCol = Rng.Find(What:="*", _
after:=Rng.Cells(1), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Column
On Error GoTo 0
If bProtected Then
SH.Protect Password:=sPassword, _
UserInterfaceOnly:=True
End If
End Function
'<<=========
- Alt+Q per chiudere l'editor di VBA e tornare a Excel
- Alt+F8 per aprire la finestra di gestione delle macro
- Seleziona Tester
- Esegui
- Salva il file problematico
Postscriptum:
Sebbene sia difficile offrire ulteriori consigli senza aver visto il file problematico, suggerirei che puoi ridurre ulteriormente il peso del file salvandolo come file xlsb.
===
Regards,
Norman