Results 1 to 5 of 5

Thread: Help VB sorting

  1. #1

    Thread Starter
    Registered User
    Join Date
    Mar 2017
    Posts
    1

    Help VB sorting

    when im using this, I can get all the data 1 to 11 from excel
    'ws.Range("details").Sort _
    'Key1:=ws.Range("srsno"), Order1:=xlascending, Header:=xlNo

    ItemNo Data
    1 1
    2 2
    3 3
    4 4
    5 5
    6 6
    7 7
    8 8
    9 9
    10 10
    11 11


    but when using this i can only get 11 to 2 correct data, 1 have the same data of 11
    'ws.Range("details").Sort _
    'Key1:=ws.Range("srsno"), Order1:=xlDescending, Header:=xlNo

    11 11
    10 10
    9 9
    8 8
    7 7
    6 6
    5 5
    4 4
    3 3
    2 2
    1 11

  2. #2
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,145

    Re: Help VB sorting

    Welcome myx!

    However, I am afraid you have posted in the wrong area of this forum. I believe this thread belongs in the Office Development section, as nothing about resembles any VB6 (and earlier) code. I'll flag the moderators and they may move it.

    If you ARE using VB6, then post again stating so...but, I suspect you may be using VBA.

    Sam

  3. #3
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,989

    Re: Help VB sorting

    Thread moved to Office Development, which is the right place for VBA/Excel questions.
    My usual boring signature: Nothing

  4. #4
    PowerPoster
    Join Date
    Oct 2008
    Location
    Midwest Region, United States
    Posts
    3,574

    Re: Help VB sorting

    How are you setting range "srsno" in both cases?

  5. #5
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Help VB sorting

    How are you setting range "srsno"
    not sure that matters, as long as it is any cell(s) in the column to be sorted by, should still work the same, even if not in the range to be sorted

    certainly it would be good to know the addresses of both named ranges, to see if any cells are missed
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

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



Click Here to Expand Forum to Full Width