sort specific column and save worksheet with sorted column in column A

rjmdc

Well-known Member
Joined
Apr 29, 2020
Messages
672
Office Version
  1. 365
Platform
  1. Windows
hi
using this code
1- how wouyld i be able to have new worksheet created named as the sorted column
2- sorted column gets either copied or moved to column A

can this be updatable each time it's run?
VBA Code:
Sub sort()
Dim SortCol As Range
'  Input box to select the column to sort by

Set SortCol = Application.InputBox("Select the column to sort", "Sort-Box", 0, , , , , 8)
Range("ALLData").sort Key1:=SortCol, Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End Sub
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Hello,

does this work as expected?

VBA Code:
Sub sort()
    Dim SortCol As Range
'  Input box to select the column to sort by
    MY_SOURCE = ActiveSheet.Name
    Set SortCol = Application.InputBox("Select the column to sort", "Sort-Box", 0, , , , , 8)
    MY_COL = SortCol.Address
    If Len(MY_COL) > 5 Then MY_LEN = 5 Else MY_LEN = 4
    MY_COL = "Column " & Mid(MY_COL, 2, Len(MY_COL) - MY_LEN) & " Sort"
    Range("ALLData").sort Key1:=SortCol, Order1:=xlAscending, Header:=xlGuess, _
        OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
        DataOption1:=xlSortNormal
'see if sorted column sheet exists
    For MY_SHEETS = 1 To ActiveWorkbook.Sheets.Count
        If Sheets(MY_SHEETS).Name = MY_COL Then GoTo cont
    Next MY_SHEETS
    Worksheets.Add After:=Sheets(ActiveWorkbook.Sheets.Count)
    MY_DEST = ActiveSheet.Name
    Sheets(MY_DEST).Name = MY_COL
    Sheets(MY_SOURCE).Select
cont:
    SortCol.Copy Sheets(MY_COL).Range("A1")
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,792
Messages
6,121,612
Members
449,038
Latest member
apwr

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top