Range and Sort Selection Issues

savem

New Member
Joined
Aug 5, 2010
Messages
1
Okay, so the task I am trying to develop a macro for involves importing a Text file, deleting colums E:J, then sorting the left over data, according to Event Type, then I am supposed to delete out all of the Pulse Events, then past a coded template from a different spreadsheet. That is not the task in its entirety, but is relevent for what I am having trouble with: Sorting the data. The big problem is that each text file I import has a variable amount of enteries, ranging from 220:280, and the sort command requires a set range. Is there any way to set a variable range, or to set the range to what is currently selected? If anyone has any Idea of how I could go about resolving this issue or any questions about what I trying to do, feel free to ask/post. I have Bolded the areas of code I am having trouble with

what I have gotten to so far is this:

ActiveCell.Offset(0, 4).Columns("A:F").EntireColumn.Select
Selection.Delete Shift:=xlToLeft
ActiveCell.Offset(5, 0).Activate
ActiveCell.CurrentRegion.Select
ActiveCell.Rows("1:5").EntireRow.Select
Selection.Delete Shift:=xlUp
ActiveCell.Cells.Select
ActiveWorkbook.Worksheets("##########").Sort.SortFields. _
Clear
ActiveWorkbook.Worksheets("###########").Sort.SortFields. _
Add Key:=ActiveCell.Offset(0, 1).Range("A1:A224"), SortOn:=xlSortOnValues, _
Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("#############").Sort
.SetRange ActiveCell.Range("A1:E224")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
ActiveCell.Rows("1:1").EntireRow.Select
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
ActiveSheet.Paste
End Sub
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,614
Messages
5,832,711
Members
430,156
Latest member
Amosjack1

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