LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 46
Default Sorting Columns using VBA

Hello,

I am writing a VBA macro that copies data from 19
worksheets on a master "roll up" sheet. Once they are all
copied, I want to sort the columns but I am having trouble
getting the sheet to sort the selection I am telling it
to. I tried the below code, but it bombs out:

Range("C2").Select
UpperLeft2 = ActiveCell.Address
Range("N2").Select
Selection.End(xlDown).Select
BottomRight2 = ActiveCell.Address
Range(UpperLeft2, BottomRight2).Select
Range(UpperLeft2, BottomRight2).sort Key1:=Range("B3"),
Order1:=xlAscending, Key2:=Range _
("E3"), Order2:=xlAscending, Header:=xlGuess,
OrderCustom:=1, MatchCase _
:=False, Orientation:=xlTopToBottom,
DataOption1:=xlSortNormal, _
DataOption2:=xlSortTextAsNumbers

Using "Selection.CurrentRegion.Select" gives me the same
area I desire, but I can't get that to work the
the ".sort" command either. The only way it will sort is
if I select the top left cell (being C2 in my example) and
then record a macro sorting how I want...but doing it this
way creates code that says, "Range("C2:C622").sort..."
which will not work for my workbook because there can, and
will be, rows of data beyond 622 in the future.

I need a more flexible solution and I have not been able
to get it to work - help!

Thanks!

- Ryan
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
freezing columns labels while sorting columns Stan New Users to Excel 1 December 3rd 09 11:30 AM
sorting 4 columns canyonhiker Excel Worksheet Functions 5 February 23rd 09 04:54 PM
help with sorting text in columns to match other columns rkat Excel Discussion (Misc queries) 1 August 11th 06 03:42 AM
Regarding Sorting Columns Ben Excel Discussion (Misc queries) 2 April 4th 05 08:05 PM
Sorting Columns JohnT Excel Worksheet Functions 3 March 5th 05 10:15 PM


All times are GMT +1. The time now is 11:25 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"