Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

If you have a complex workbook with many sheets and you aren't sure how large it is, here's a simple macro you can use for calculating the total number of cells and approximate memory required:Private Sub Workbook_Open()
MsgBox ("Worksheet count: " & ActiveWorkbook.Worksheets.Count)
Dim cellcount As Double
cellcount = 0
For Each Sheet In ActiveWorkbook.Worksheets
cellcount = cellcount + Sheet.UsedRange.Cells.Count
'MsgBox (Sheet.Name & ": " & Sheet.UsedRange.Cells.Count)
Next
Dim message As String
message = "Total cells in workbook: " & vbCrLf & FormatNumber(Round(cellcount), 0) & vbCrLf
message = message & "Approximate memory required (at 300 bytes per cell): " & vbCrLf & FormatNumber(Round(cellcount * 300), 0) & " bytes " & vbCrLf & Math.Round(((cellcount / 1024 / 1024 / 1024) * 300), 2) & " gigabytes"
MsgBox (message)
End Sub
  Vbnet11

Vbnet
4
4

Private Sub CalculateCells()
Dim cellcount As Double
Dim Sheet
cellcount = 0
For Each Sheet In ActiveWorkbook.Worksheets
cellcount = cellcount + Sheet.UsedRange.Cells.Count
Next
Dim message As String
message = "Total cells in workbook: " & vbCrLf & FormatNumber(Round(cellcount), 0) & vbCrLf
message = message & "Approximate memory required (at 400 bytes per cell): " & vbCrLf & FormatNumber(Round(cellcount * 400), 0) & " bytes " & vbCrLf & Math.Round(((cellcount / 1024 / 1024 / 1024) * 400), 2) & " gigabytes"
MsgBox (message)

End Sub

Best Practices for Large Reports

...