Share via

[SOLVED] How to code this macro?

Anonymous
2022-05-11T06:40:25+00:00

Referring to following online file, I would like to know on how to sort data from column B (original) into column D (Case 2) format using macro

Blank space affects the sorting order, is there any approach to solve this issue?

Range("C3:C8").Select  
Selection.Sort Key1:=Range("C3"), Order1:=xlAscending, Header:=xlGuess, \_  
    OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, SortMethod \_  
    :=xlStroke, DataOption1:=xlSortNormal  

Does anyone have any suggestions?
Thanks in advance

Online file: https://1drv.ms/x/s!AuvJV0hx3xTGiQ1whF9SDpIxuKO_?e=lcc9P4

Microsoft 365 and Office | Excel | Other | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

5 answers

Sort by: Most helpful
  1. Anonymous
    2022-05-15T13:54:11+00:00

    I use another approach to sort those data, problem is solved.

    Thank you very much for suggestions (^v^)

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments
  2. Anonymous
    2022-05-12T12:33:00+00:00

    In the code that I shared, I copied first the value column B to D so that it will remove some formatting and make sure that the blank cell is really empty.

    It seems that the column B in your current sheet have some formatting that needs to be reset.

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments
  3. Anonymous
    2022-05-11T15:09:34+00:00

    When I try your given code on new worksheet, it works fine, but it does not work on my existing worksheet.

    Sub sortcase3()
    Range("B4:B1300").Select
    Selection.Sort Key1:=Range("B4"), Order1:=xlAscending, Header:=xlGuess, _
    OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, SortMethod _
    :=xlStroke, DataOption1:=xlSortNormal
    Application.CutCopyMode = False
    Range("B3").Select
    End Sub

    Is there anything wrong with this workbook?

    Do you have any suggestions?

    Thank you very much for any suggestions (^v^)

    Online file : https://1drv.ms/x/s!AuvJV0hx3xTGiQ6VzSTX_Nvz91oM?e=ePuHU3

    Was this answer helpful?

    0 comments No comments
  4. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  5. Anonymous
    2022-05-11T07:40:41+00:00

    Hi oemSoft, hope you're doing well. I’m Ian, and I’m happy to help you today.

    Sub sortcase2()
        Range("D3:D8").Value = Range("B3:B8").Value
        Range("D3:D8").Select
        Selection.Sort Key1:=Range("D3"), Order1:=xlAscending, Header:=xlGuess, _
        OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, SortMethod _
        :=xlStroke, DataOption1:=xlSortNormal
    End Sub
    

    This is a user-to-user support forum and I am a fellow user.

    I hope this helps, but please let me know if you need anything else.

    Was this answer helpful?

    0 comments No comments