Sorting - should have been easy

R

Ron

I have a worksheet open, so it is the active worksheet and did some stuff,
ending with 27 rows (number of rows will vary each day, but should get above
35 to 40), A-E. Need to sort from A5 down. Started at A1. Recording Macro
said:

ActiveCell.Offset(4, 0).Range("A1:E31").Select
ActiveWorkbook.Worksheets("prysm06-17-09").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("prysm06-17-09").Sort.SortFields.Add Key:= _
ActiveCell.Range("A1:A23"), SortOn:=xlSortOnValues,
Order:=xlAscending, _
DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("prysm06-17-09").Sort
.SetRange ActiveCell.Range("A1:E23")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With

I want to use this on a different file each day, so name wil be different.
How do I get past ActiveWorkbook.Worksheets("prysm06-17-09"). and just sort
on the sheet that open, with out naming the file each time. My syntax
sucks.... :)

Thanks,

Ron
 
R

Ron

Guess I wasn't patient enough. Changed it to ActiveWorkbook.ActiveSheet.Sort
and it worked.

Thanks anyway.
 
P

Patrick Molloy

Option Explicit
Sub test()
Dim source As Range
With ActiveSheet
Set source = .Range(.Range("A5"), .Range("E5").End(xlDown))
End With

source.Sort source.Range("A1"), xlAscending


End Sub
 
R

Ron

That worked so much better.

Thanks Patrick

Ron

Patrick Molloy said:
Option Explicit
Sub test()
Dim source As Range
With ActiveSheet
Set source = .Range(.Range("A5"), .Range("E5").End(xlDown))
End With

source.Sort source.Range("A1"), xlAscending


End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Applying Variables to SORT 4
Undo Macro Action 3
vba dynamic 1
Clear Check Box 2
VBA 2 Codes 2
Sorting Question 5
Sort by one column then another. 2
Problem with Worksheet Activate and Sorting 7

Top