Excel VBA Macro: Check Size of Each Worksheet (in Current Workbook)

  Рет қаралды 637

greggowaffles

greggowaffles

Жыл бұрын

Excel VBA Macro: Check Size of Each Worksheet (in Current Workbook). Find out which parts of an Excel workbook are the biggest in size.
💥Subscribe: / @greggowaffles
Code:
Sub worksheet_sizes()
Dim i As Integer
Dim row_count As Integer
Dim tab_check As Integer
Dim tab_count As Integer
Dim tab_name As String
Dim sh As String
Dim temp_book As String
Dim ws As Worksheet
Dim new_tab As Worksheet
Application.ScreenUpdating = False
tab_check = 0
tab_count = Sheets.Count
tab_name = "Worksheet Sizes"
For i = 1 To tab_count
If Sheets(i).Name = tab_name Then
tab_check = 1
End If
Next i
If tab_check = 0 Then
ThisWorkbook.Worksheets.Add(before:=Application.Worksheets(1)).Name = tab_name
End If
temp_book = ThisWorkbook.Path & "\Temp.xls"
Set new_tab = Application.Worksheets(tab_name)
With new_tab
.Cells.Clear
.Cells(1, 1) = "Name"
.Cells(1, 2) = "Size (KB)"
End With
For Each ws In ActiveWorkbook.Worksheets
If ws.Name <> tab_name Then
ws.Copy
ActiveWorkbook.SaveAs temp_book
ActiveWorkbook.Close savechanges:=False
new_tab.Activate
row_count = WorksheetFunction.CountA(Range("A1", Range("A1").End(xlDown)))
With new_tab
.Cells(row_count + 1, 1) = ws.Name
.Cells(row_count + 1, 2) = FileLen(temp_book) / 1000
End With
Kill temp_book
End If
Next
Application.ScreenUpdating = True
End Sub
#excelvba #excelmacro

Пікірлер: 8
@deepk82
@deepk82 4 ай бұрын
Great share
@Jojosmith342
@Jojosmith342 Жыл бұрын
thank you very much Greg for the code & clear video. Always thumb up from the beginning class 👍
@ahmed007Jaber
@ahmed007Jaber 5 ай бұрын
Thank you Greg Just wondering if you checked the sum of all sheets and if it equaled the original file I will definitely check it out in the morning. Was trying to do this today
@alializadeh8195
@alializadeh8195 Жыл бұрын
Thanx
@greggowaffles
@greggowaffles Жыл бұрын
No prob! Thanks for watching!!
@jonnathanjon1
@jonnathanjon1 Жыл бұрын
Hi I was trying to show this in a pop up message box using msgbx syntax instead of showing in a new sheet. Can you help?
@greggowaffles
@greggowaffles Жыл бұрын
hi Johnathan! yup! hope this helps! Sub worksheet_sizes_w_msgbox() Dim temp_book As String Dim ws As Worksheet Dim message As String Application.ScreenUpdating = False temp_book = ThisWorkbook.Path & "\Temp.xls" For Each ws In ActiveWorkbook.Worksheets ws.Copy ActiveWorkbook.SaveAs temp_book ActiveWorkbook.Close savechanges:=False message = message & ws.Name & ": " & _ FileLen(temp_book) / 1000 & " KB" & vbNewLine Kill temp_book Next Application.ScreenUpdating = True MsgBox message End Sub
@greggowaffles
@greggowaffles Жыл бұрын
made a video too! kzbin.info/www/bejne/hmqvZJyhj9B5q6M
VBA Macro to Copy Data from Another Workbook in Excel
13:39
Excel Campus - Jon
Рет қаралды 635 М.
Spot The Fake Animal For $10,000
00:40
MrBeast
Рет қаралды 178 МЛН
路飞太过分了,自己游泳。#海贼王#路飞
00:28
路飞与唐舞桐
Рет қаралды 31 МЛН
Secret Experiment Toothpaste Pt.4 😱 #shorts
00:35
Mr DegrEE
Рет қаралды 32 МЛН
No empty
00:35
Mamasoboliha
Рет қаралды 8 МЛН
Excel VBA To Copy Data From One Sheet To Another (BEGINNER TO PRO!)
11:46
Tiger Spreadsheet Solutions
Рет қаралды 97 М.
How to Get List of File Names in a Folder using Excel
5:40
Excel Weez
Рет қаралды 6 М.
Class Modules in VBA: Made Super Simple
17:43
Excel Macro Mastery
Рет қаралды 31 М.
White Guy Orders in Chinese at Drive Thru, But When He Pulls Up…
2:45
Xiaomanyc 小马在纽约
Рет қаралды 15 МЛН
10 awesome Power Query tricks you NEED to know! | Excel Off The Grid
15:44
Excel Off The Grid
Рет қаралды 34 М.
Excel VBA Macro: Send Multiple Emails (with Multiple Attachments)
12:09
12 Pro PivotTable Formatting Tricks = No more UGLY PivotTables!
12:12
MyOnlineTrainingHub
Рет қаралды 329 М.
Spot The Fake Animal For $10,000
00:40
MrBeast
Рет қаралды 178 МЛН