+ Reply to Thread
Results 1 to 5 of 5

Sorting columns during sheet deactivation

  1. #1
    Registered User
    Join Date
    08-01-2013
    Location
    Gaydon
    MS-Off Ver
    Excel 2010
    Posts
    3

    Sorting columns during sheet deactivation

    Hi,

    I would like to sort some columns alphabetically when deactivating a sheet. If I use the Worksheet_Deactivate command to trigger the macro then it immediately needs activating again to do the sorting, hence an infinite loop is started.

    So far I have:

    Private Sub Worksheet_Deactivate()

    Application.ScreenUpdating = False

    Worksheets("Data Library").Columns("C:X").Select
    Selection.Sort Key1:=Range("C2"), Order1:=xlAscending, Header:=xlGuess, _
    OrderCustom:=1, MatchCase:=False, Orientation:=xlLeftToRight, _
    DataOption1:=xlSortNormal
    ActiveWindow.LargeScroll ToRight:=-1

    Application.ScreenUpdating = True

    End Sub

    This fails to run on the 'Worksheets..' line.

    Please can anybody help?

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Sorting columns during sheet deactivation

    Hi, pnewbury,

    please use code-tags when you are showing porcedures here in the forum.

    Avoid reactivating the sheet like using a With-Statement
    Please Login or Register  to view this content.
    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Registered User
    Join Date
    08-01-2013
    Location
    Gaydon
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Sorting columns during sheet deactivation

    That seems to work perfectly, thanks very much Holger!

  4. #4
    Registered User
    Join Date
    08-01-2013
    Location
    Gaydon
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Sorting columns during sheet deactivation

    I can't see how to mark this thread as 'solved'

  5. #5
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Sorting columns during sheet deactivation

    Quote Originally Posted by pnewbury View Post
    I can't see how to mark this thread as 'solved'
    FYI.

    "mark your thread as Solved: Click Thread Tools above your first post, select "Mark your thread as Solved". Or click the Edit button on your first post in the thread, Click Go Advanced, select [SOLVED] from the Prefix dropdown, then click Save Changes."

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 2
    Last Post: 07-03-2013, 06:17 PM
  2. [SOLVED] Exporting specific data columns from sheet and sorting by string
    By ardais in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 05-04-2012, 12:43 AM
  3. sorting two columns and write the sorted values on two columns in a different sheet
    By virsojour in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-22-2010, 04:38 AM
  4. Sorting rows and moving columns in a locked sheet.
    By agentscreech in forum Excel General
    Replies: 5
    Last Post: 08-30-2010, 10:11 PM
  5. Prevent deactivation of sheet
    By Kobus in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-15-2005, 06:06 AM

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