+ Reply to Thread
Results 1 to 2 of 2

Clearing data and assigning a new value upon close

  1. #1
    Registered User
    Join Date
    01-25-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    5

    Clearing data and assigning a new value upon close

    I'm creating a PO Form for our company. I have most things working perfectly: a button to save the form exports it as a pdf and then clears all data and assigns the next number and a button to clear the form does just that and assigns the next number. I have numerous cells locked and password protected so no one can change the form or fudge the numbers. However I want to have a new PO Number automatically assigned and all data cleared upon either (preferably) close or open of the PO Form with a confirmation message saying so. And I want the workbook to automatically save without giving the option.

    I'm very new to macros and have built my code so far from the help of this forum and other Google searches. I am trying this "BeforeClose" under "ThisWorkbook" but the dubugger hates my lines to change the value of a cell (H3) and ClearContents of my main worksheet. I've tried "Worksheet("PO Form").Range(etc" but it didn't work wither. Help would be appreciated.

    Please Login or Register  to view this content.
    Last edited by JBeaucaire; 01-25-2013 at 08:39 PM. Reason: Added code tags, as per forum rules. Don't forget!

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Clearing data and assigning a new value upon close

    First, you "snip" appears to include the start of another sub, then the Workbook_BeforeClose macro. Make sure you don't have that error in your workbook, too!

    Macros in the ThisWorkbook module are global. Anything you construct in there must include full addressing to the correct sheet. Your "Range" command has no parent sheet indicated, so the macro doesn't know where to apply that range command.

    Please Login or Register  to view this content.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1