Ask a questionAsk a question
 

AnswerSaving a worksheet

  • Thursday, November 05, 2009 8:22 PMs7yzrs Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hello! I have this workbook with 6 worksheets. Worksheet1 is the one that will "distribute" the data to all the others. Before closing the application I need all data to be saved in all sheets but sheet1 which I need to be empty. Data in sheet1 is input using a userform and this has to be cleared too before closing. If possible I would like the userform to have just one button for bringing the data to the sheets (done that), printing the active sheet (done that too) clearing both userform and sheet1, saving the workbook and exit excel. Is this all possible?

    thanks for any help

Answers

  • Thursday, November 05, 2009 9:08 PMsuznal Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     AnswerHas Code
    Yes it is...

    add to the buttons code...

    'clear sheet1
        Sheets("Sheet1").Cells.Select
        Selection.ClearContents
        
    'Save the workbook
        ActiveWorkbook.Save
        
        
    'Close Excel
        Application.Quit
    
    When you close the Userform and re-open excel the userform fields should be empty. If you really want to clear them just specify that the values are "", for example...


    With UserForm1
        .TextBox1.Value = ""
        .TextBox2.Value = ""
    End With
    
    'Then close the Userform
    Unload UserForm1
    
    That should get you started.


    "The new phonebooks are here!"
    • Marked As Answer bys7yzrs Thursday, November 05, 2009 9:23 PM
    •  

All Replies

  • Thursday, November 05, 2009 9:08 PMsuznal Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     AnswerHas Code
    Yes it is...

    add to the buttons code...

    'clear sheet1
        Sheets("Sheet1").Cells.Select
        Selection.ClearContents
        
    'Save the workbook
        ActiveWorkbook.Save
        
        
    'Close Excel
        Application.Quit
    
    When you close the Userform and re-open excel the userform fields should be empty. If you really want to clear them just specify that the values are "", for example...


    With UserForm1
        .TextBox1.Value = ""
        .TextBox2.Value = ""
    End With
    
    'Then close the Userform
    Unload UserForm1
    
    That should get you started.


    "The new phonebooks are here!"
    • Marked As Answer bys7yzrs Thursday, November 05, 2009 9:23 PM
    •  
  • Thursday, November 05, 2009 9:15 PMs7yzrs Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    suz, thanks for the reply. I forgot to mention that sheet1 contains formulas too. Will I keep them using your code?
  • Thursday, November 05, 2009 9:23 PMs7yzrs Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    No sorry, I must be tired. Everything works just as you said!!!!

    thanks for your help