Consulting

Results 1 to 6 of 6

Thread: Probably simple VBA issue

  1. #1
    VBAX Regular
    Joined
    Mar 2009
    Posts
    25
    Location

    Probably simple VBA issue

    Hi all,

    I've got a problem with below code. Autofitler works fine but not the built in sort function. my sheet has no protected cells so I wonder why it dosen't work.

    Please help

    Best regards
    Per

    [VBA]Sub testavsortera()
    Dim ws As Worksheet
    For Each ws In ThisWorkbook.Worksheets
    ws.Protect Password:="test", userinterfaceonly:=True, AllowSorting:=True
    ws.EnableAutoFilter = True
    'ws.EnableSelection = xlNoRestrictions
    ws.Protect
    Next ws
    End Sub[/VBA]

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    I think I have mentioned this before that the AllowSorting option seems to just enqable or disable the Sort button, it doesn't actually allow you to sort the data (real genius that thought up that combination!).

    You need to unprotect it in VBA, sort it, then protect it again.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Regular
    Joined
    Mar 2009
    Posts
    25
    Location
    Quote Originally Posted by xld
    I think I have mentioned this before that the AllowSorting option seems to just enqable or disable the Sort button, it doesn't actually allow you to sort the data (real genius that thought up that combination!).

    You need to unprotect it in VBA, sort it, then protect it again.
    My cells are only hidden not protected but I still can't get it to work.

    Per

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by percy4
    My cells are only hidden not protected
    Quote Originally Posted by percy4
    [vba]

    ws.Protect Password:="test", userinterfaceonly:=True, AllowSorting:=True
    [/vba]
    Those two statements seem contradictory to me.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    VBAX Regular
    Joined
    Mar 2009
    Posts
    25
    Location
    Quote Originally Posted by xld
    Those two statements seem contradictory to me.
    Hmm thats right. But the settings for the cells are not locked. I've unchecked that box (in cell properties).

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Doesn't matter, the sheet is protected. My previous comment stands.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

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