I need help. I know it's not the most difficult thing to do, but I just can't figure it out.
Sounds very easy, but I just can't find any info. Of course maybe because I've been working for the past 12 hours.
Anyways, here is what I need to do:
I have a macro that is processing multiple csv files, extracts data from them and than puts into a report. I need to get the files sorted by one of the columns to speed up the data population into the report. The problem is that the csv files have a header of 4 rows that i want to keep intact and just sort the data from row 5 all the way down. I use the below code and it keeps on sorting th whole file including the first 4 rows.
I would really appreciate if you could help. Thank you in advance.
With ActiveSheet
cl = .UsedRange.Columns.Count
rw = .UsedRange.Rows.Count
.UsedRange.Select
End With
' *****
Set MyRange = Selection
With MyRange
.Offset(3, 0).Resize(Selection.Rows.Count - 3, Selection.Columns.Count).Select
End With
Cells.Sort Key1:=MyRange, Order1:=xlAscending, Header:=xlYes, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
Last edited by Vaniok; 12-04-2009 at 11:05 AM. Reason: Changed Title
Welcome to the forum,
Your post does not comply with Rule 1 of our Forum RULES. Your post title should accurately and concisely describe your problem, not your anticipated solution. Use terms appropriate to a Google search. Poor thread titles, like Please Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will be addressed according to the OP's experience in the forum: If you have less than 10 posts, expect (and respond to) a request to change your thread title. If you have 10 or more posts, expect your post to be locked, so you can start a new thread with an appropriate title.
To change a Title on your post, click EDIT then Go Advanced and change your title, if 2 days have passed ask a moderator to do it for you.
Microsoft MVP - Excel
Where there is a will there are many ways. Pick One!
Please read the Forum Rules
If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below
Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.
Preferred Charities: Lupus Canada and Sick Kids Foundation.
Feel Free to Donate if you want to, for the assistance you received today.
Try this, you must change the worksheet name to fit:
Code:Dim RRows As Integer Dim CCols As Integer With ActiveSheet cl = .UsedRange.Columns.Count rw = .UsedRange.Rows.Count .UsedRange.Select End With ' ***** Set MyRange = Selection With MyRange .Offset(4, 0).Resize(Selection.Rows.Count - 4, Selection.Columns.Count).Select End With RRows = Selection.Rows.Count CCols = Selection.Columns.Count With Worksheets("Sheet1").Sort .SetRange Range(Cells(1, 1), Cells(RRows, CCols)) .Header = xlNo .MatchCase = False .Orientation = xlTopToBottom .SortMethod = xlPinYin .Apply End With
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks