Gringoire
Board Regular
- Joined
- Nov 18, 2016
- Messages
- 71
- Office Version
- 365
- Platform
- Windows
Hi,
I have a worksheet called DATA in Excel files (called Master) where I load data from others excel files.
Sometimes I need to load a huge amount of data (about 10.000.000 cells) but the most of times I just need about 100.000 cells.
The point is that once I loaded a big amount of data (280.000 rows) the UsedRange always preserve these monstruous dimensions and filesize increase from 1,5Mb to about 50Mb, making it very slow.
I already tried to reduce UserRange by VBA using some snippet like this one:
but it doesn't work.
I also tried this (found by Google):
but I had to Ctrl+Break because after 20 minutes it was still working on a UsedRange of about 240.000 rows.
Does it exist a simple way to reduce the UsedRange?
thank you.
I have a worksheet called DATA in Excel files (called Master) where I load data from others excel files.
Sometimes I need to load a huge amount of data (about 10.000.000 cells) but the most of times I just need about 100.000 cells.
The point is that once I loaded a big amount of data (280.000 rows) the UsedRange always preserve these monstruous dimensions and filesize increase from 1,5Mb to about 50Mb, making it very slow.
I already tried to reduce UserRange by VBA using some snippet like this one:
Code:
Sub Macro1()ActiveSheet.UsedRange
ActiveSheet.UsedRange.Clear
a = ActiveSheet.UsedRange.Rows.Count
ActiveWorkbook.Save
End Sub
but it doesn't work.
I also tried this (found by Google):
Code:
Public Sub delete_empty_row() Application.ScreenUpdating = False
For Each usedrng In ActiveSheet.UsedRange
If usedrng.MergeCells = True Then
If usedrng.Value = "" Then
usedrng.Value = ""
End If
Else
If usedrng.Value = "" Then
usedrng.ClearContents
End If
End If
Next
ActiveSheet.UsedRange
usedRangeLastColNum = ActiveSheet.UsedRange.Columns.Count
usedrangelastrow = ActiveSheet.UsedRange.Rows.Count
For r = usedrangelastrow To 1 Step -1
If Application.WorksheetFunction.CountA(Cells(r, usedRangeLastColNum).EntireRow) <> 0 Then
Exit For
Else
Cells(r, usedRangeLastColNum).EntireRow.Delete
End If
Next r
For c = usedRangeLastColNum To 1 Step -1
If Application.WorksheetFunction.CountA(Cells(1, c).EntireColumn) <> 0 Then
Exit For
Else
Cells(1, c).EntireColumn.Delete
End If
Next c
ActiveSheet.UsedRange
Application.ScreenUpdating = True
End Sub
but I had to Ctrl+Break because after 20 minutes it was still working on a UsedRange of about 240.000 rows.
Does it exist a simple way to reduce the UsedRange?
thank you.