Solved

Delete data on close

Posted on 2013-10-28
4
251 Views
Last Modified: 2013-10-28
How would I go about deleting data from an entire section upon closing the workbook.  

I would like to delete the range B2:J1000 at the close.

Any ideas?  thanks,
0
Comment
Question by:BostonBob
4 Comments
 
LVL 16

Expert Comment

by:Peter Kwan
ID: 39607567
Please see if the attached works for you.
Testworkbook.xlsm
0
 

Author Comment

by:BostonBob
ID: 39607737
I was just about to say the same thing.  thanks.
0
 
LVL 81

Accepted Solution

by:
byundt earned 500 total points
ID: 39607739
The following macro (which must be installed in the ThisWorkbook code pane) will clear cells B2:J1000 from the first worksheet in the workbook, then save the file. It is triggered by the user trying to close the workbook.
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Worksheets(1).Range("B2:J1000").ClearContents
ThisWorkbook.Save
End Sub

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Window placement 17 77
DO Loop not working 4 72
Write data from SQL to CSV file - position 1 53
Macro which automatically send Excel spreadsheet to Outlook problem 2 61
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now