+ Reply to Thread
Results 1 to 9 of 9

Autofit and sort on workbook close

  1. #1
    Registered User
    Join Date
    06-05-2007
    Posts
    81

    Autofit and sort on workbook close

    Good morning,
    I am trying to manipulate some worksheets during a Workbook_BeforeClose event. On sheet names that end with "sd" they need to alphabetize the data and autofit the columns. All sheets should hide on close, except "order". This is what I have but warning - it did something bad to my workbook. I can't get it back again. Had to force close Excel.

    Please Login or Register  to view this content.
    Thank you for any help. Most appreciated!!
    Last edited by pprseller; 12-22-2009 at 02:54 PM.

  2. #2
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Autofit and sort on workbook close

    Maybe:

    Please Login or Register  to view this content.
    Your main problem appears that for worksheets named as *sd it was not doing anything with them. The sort and autofit would always have been performed on what was the active sheet at the time.

    You were also including all the cells in the worksheet in the sort, I've assumed your table in each worksheet starts in cell A1 and is a contiguous block of data.

    Dom
    Last edited by Domski; 12-22-2009 at 12:02 PM. Reason: Added missing .
    "May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."

    Use code tags when posting your VBA code: [code] Your code here [/code]

    Remember, saying thanks only takes a second or two. Click the little star to give some Rep if you think an answer deserves it.

  3. #3
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,239

    Re: Autofit and sort on workbook close

    You missed one:
    Please Login or Register  to view this content.
    Remember what the dormouse said
    Feed your head

  4. #4
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Autofit and sort on workbook close

    Quote Originally Posted by romperstomper View Post
    You missed one:
    Please Login or Register  to view this content.
    Indeed I did, thanks.

    Dom

  5. #5
    Registered User
    Join Date
    06-05-2007
    Posts
    81

    Re: Autofit and sort on workbook close

    Thank you, Domski and romperstomper. I appreciate the help but it's still autofitting the "order" sheet and it shouldn't. It will be the active sheet on the close event but the name is just "order", not "*sd", so it shouldn't autofit.
    (Thank you for the advice too. I'm still learning and telling me where I went wrong is most helpful.)

    It's also sorting my header columns into the data. I changed the range to "A2".CurrentRegion. Still didn't help. Thanks .......
    Last edited by pprseller; 12-22-2009 at 12:47 PM.

  6. #6
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Autofit and sort on workbook close

    Are you sure you don't have some other code that's doing that to the Order sheet as what I have posted definitely won't.

    Dom

  7. #7
    Registered User
    Join Date
    06-05-2007
    Posts
    81

    Re: Autofit and sort on workbook close

    I will go through it again. Good chance I do. I am winging most of what've I got. :-) I just changed my last post, problem with the sort. Is that from the currentregion or something that I am doing?

  8. #8
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Autofit and sort on workbook close

    Try changing this line:

    Please Login or Register  to view this content.
    Dom

  9. #9
    Registered User
    Join Date
    06-05-2007
    Posts
    81

    Re: Autofit and sort on workbook close

    Thank you for all your help. I think I have figured out the problem and it was my error. I appreciate your assistance!!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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