-
Dec 3rd, 2010, 01:07 PM
#1
Thread Starter
New Member
[RESOLVED] Sorting Excel 2007 using VB 2010
I'm trying to sort a range in excel 2007, copy it and export it to another workbook. I can get as far as selecting the range but, I get lost after that...I have searched a lot of threads but, just can't seem to find one that give me an exact answer. Any help would be appreciated.
Mike
-
Dec 3rd, 2010, 03:38 PM
#2
Hyperactive Member
Re: Sorting Excel 2007 using VB 2010
Why don't you try to use the Macro Recorder in Excel and look at the codes in VBA. Might help get you started.
-
Dec 3rd, 2010, 03:50 PM
#3
Re: Sorting Excel 2007 using VB 2010
Here's code I had laying around to AutoFilter and Sort and Excel.Range
Code:
Dim Range As Excel.Range
Range = ws.Range("A1:G50")
Range.AutoFilter(1, , Excel.XlAutoFilterOperator.xlAnd, , True)
Range.Sort(Key1:=Range.Columns(1), Order1:=Excel.XlSortOrder.xlAscending, _
Orientation:=Excel.XlSortOrientation.xlSortColumns, _
Header:=Excel.XlYesNoGuess.xlNo, _
SortMethod:=Excel.XlSortMethod.xlPinYin, _
DataOption1:=Excel.XlSortDataOption.xlSortNormal, _
DataOption2:=Excel.XlSortDataOption.xlSortNormal, _
DataOption3:=Excel.XlSortDataOption.xlSortNormal)
-
Dec 3rd, 2010, 04:04 PM
#4
Thread Starter
New Member
Re: Sorting Excel 2007 using VB 2010
Thank you Matt. Your code works for me. I really appreciate it.
Mike
-
Apr 7th, 2011, 10:23 AM
#5
New Member
Re: [RESOLVED] Sorting Excel 2007 using VB 2010
This code works great, but what if one column that I want to sort by is a date? Currently it's reading it as a string and then sorting by day then month. Any solutions?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|