Solved

Delete data on close

Posted on 2013-10-28
4
256 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

738 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