Sorting ActiveWorkbook

mn_voyageur

New Member
Joined
Aug 7, 2018
Messages
5
Just starting to learn the details of VBA.

Recorded the following for sorting based upon Column A.

Does "8_7_18 CSV Report" prevent the sort from executing, if the worksheet is not "8_7_18 CSV Report"? If so, how do I make this more generic? (Run on the active worksheet.)

Thanks,
MarkN

Sub Macro6()
'
' Macro6 Macro
'

'
Columns("A:A").Select
Application.CutCopyMode = False
Selection.Cut
Columns("D:D").Select
ActiveSheet.Paste
Columns("A:A").Select
Selection.Delete Shift:=xlToLeft
Cells.Select
ActiveWorkbook.Worksheets("8_7_18 CSV Report").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("8_7_18 CSV Report").Sort.SortFields.Add Key:=Range _
("A1:A236"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("8_7_18 CSV Report").Sort
.SetRange Range("A1:I236")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Hi & welcome to MrExcel.
Try
Code:
Sub Macro6()
'
' Macro6 Macro
'

'
Columns("A:A").Select
Application.CutCopyMode = False
Selection.Cut
Columns("D:D").Select
ActiveSheet.Paste
Columns("A:A").Select
Selection.Delete Shift:=xlToLeft
Cells.Select
ActiveSheet.Sort.SortFields.Clear
ActiveSheet.Sort.SortFields.Add key:=Range _
("A1:A236"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveSheet.Sort
.SetRange Range("A1:I236")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
 
Upvote 0
Another way:

Code:
Sub Macro6()
  Range("A:A").Cut Range("D:D")
  Range("A:A").Delete
  Range("A:I").Sort Key1:=Range("A1"), Header:=xlYes
End Sub
 
Upvote 0
I appreciate the help. I have the CSV file cleaned up.

I was hoping to attach the resulting xlsx file, because I am having difficulty pulling the "rider" and times. If someone can tell me how to attach the file, I will. Otherwise, my formula is:
{=IFERROR(INDEX(Sheet1!A6:B103,SMALL(IF(Sheet1!A6:B103=$A$1,ROW(Sheet1!$A$1:$B$98)),ROW(6:6)),2)," ")}

It works, but not exclusively, nor consistently. Is there an easier way to pull the rider number from column A and the time stamp from column B?

MarkN
 
Upvote 0
As this is a completely different question, can you please start a new thread.
 
Upvote 0
If I wanted to sort by column A and then column B using this as an example:
Range("A:I").Sort Key1:=Range("A1"), Header:=xlYes​

What would I add?

MarkN
 
Upvote 0

Forum statistics

Threads
1,213,546
Messages
6,114,256
Members
448,558
Latest member
aivin

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