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

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
59,920
Office Version
  1. 365
Platform
  1. Windows
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
 

shg

MrExcel MVP
Joined
May 7, 2008
Messages
21,797
Office Version
  1. 2010
Platform
  1. Windows
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
 

mn_voyageur

New Member
Joined
Aug 7, 2018
Messages
5
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
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
59,920
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

As this is a completely different question, can you please start a new thread.
 

mn_voyageur

New Member
Joined
Aug 7, 2018
Messages
5
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
 

Forum statistics

Threads
1,136,326
Messages
5,675,116
Members
419,551
Latest member
thangxpm

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
Top