Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Clear workbook
Hi all,
I need to add a piece of code at the beginning of my program that checks if the workbook is empty or not (I just want 3 blank sheets). And if it is not empty (charts, sheets with data...) it needs to clear/delete everything and keep only 3 blank sheets.... Thanks a lot! |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Clear workbook
Why not just start a new workbook with 3 worksheets?
Option Explicit Sub testme() Dim NewWkbk As Workbook Dim CurSheetsInWorkbook As Long CurSheetsInWorkbook = Application.SheetsInNewWorkbook Application.SheetsInNewWorkbook = 3 Set NewWkbk = Workbooks.Add Application.SheetsInNewWorkbook = CurSheetsInWorkbook 'then work with newwkbk End Sub Lucile wrote: Hi all, I need to add a piece of code at the beginning of my program that checks if the workbook is empty or not (I just want 3 blank sheets). And if it is not empty (charts, sheets with data...) it needs to clear/delete everything and keep only 3 blank sheets.... Thanks a lot! -- Dave Peterson |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Clear workbook
Better to start with fresh, clean, sheets rather than try to launder the old
ones: Sub cleanup() Worksheets.Add befo=Worksheets(1) Worksheets.Add befo=Worksheets(1) Worksheets.Add befo=Worksheets(1) n = Worksheets.Count For i = n To 4 Step -1 Application.DisplayAlerts = False Sheets(i).Delete Next End Sub -- Gary''s Student - gsnu200830 "Lucile" wrote: Hi all, I need to add a piece of code at the beginning of my program that checks if the workbook is empty or not (I just want 3 blank sheets). And if it is not empty (charts, sheets with data...) it needs to clear/delete everything and keep only 3 blank sheets.... Thanks a lot! |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Clear workbook
Excellent!
Thank you very much! "Gary''s Student" wrote: Better to start with fresh, clean, sheets rather than try to launder the old ones: Sub cleanup() Worksheets.Add befo=Worksheets(1) Worksheets.Add befo=Worksheets(1) Worksheets.Add befo=Worksheets(1) n = Worksheets.Count For i = n To 4 Step -1 Application.DisplayAlerts = False Sheets(i).Delete Next End Sub -- Gary''s Student - gsnu200830 "Lucile" wrote: Hi all, I need to add a piece of code at the beginning of my program that checks if the workbook is empty or not (I just want 3 blank sheets). And if it is not empty (charts, sheets with data...) it needs to clear/delete everything and keep only 3 blank sheets.... Thanks a lot! |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Clear workbook
For future reference, these 3 lines...
Worksheets.Add befo=Worksheets(1) Worksheets.Add befo=Worksheets(1) Worksheets.Add befo=Worksheets(1) can be replaced by this single line... Worksheets.Add Befo=Worksheets(1), Count:=3 -- Rick (MVP - Excel) "Gary''s Student" wrote in message ... Better to start with fresh, clean, sheets rather than try to launder the old ones: Sub cleanup() Worksheets.Add befo=Worksheets(1) Worksheets.Add befo=Worksheets(1) Worksheets.Add befo=Worksheets(1) n = Worksheets.Count For i = n To 4 Step -1 Application.DisplayAlerts = False Sheets(i).Delete Next End Sub -- Gary''s Student - gsnu200830 "Lucile" wrote: Hi all, I need to add a piece of code at the beginning of my program that checks if the workbook is empty or not (I just want 3 blank sheets). And if it is not empty (charts, sheets with data...) it needs to clear/delete everything and keep only 3 blank sheets.... Thanks a lot! |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Still need help - Clear a cell upon workbook Close | Excel Discussion (Misc queries) | |||
clear cells when workbook is opened | Excel Discussion (Misc queries) | |||
How to clear links to external workbook | Excel Programming | |||
Trying get macro to clear cells when workbook is opened. | Excel Programming | |||
clear data from workbook | Excel Worksheet Functions |