View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Roger Govier[_8_] Roger Govier[_8_] is offline
external usenet poster
 
Posts: 376
Default Ending Macro in Last Row within a column of Printable Items

Hi Mike

The following code assumes your headers are in row 1.
It counts the number of rows with entries in columnA, and the number of
columns with data in row 1.

It then sorts that selection by ColumnA Ascending followed by column B
ascending.
Adjust to suit

Sub SortData()
Dim lr As Long, lc As Long
lr = Cells(Rows.Count, 1).End(xlUp).Row
lc = Cells(1, Columns.Count).End(xlToLeft).Column

Range(Cells(1, 1), Cells(lr, lc)).Select
Selection.Sort Key1:=Range("A1"), Order1:=xlAscending, _
Key2:=Range("B1"), Order2:=xlAscending, _
Header:=xlYes, OrderCustom:=1, _
MatchCase:=False, Orientation:=xlTopToBottom

End Sub

--
Regards
Roger Govier

MrMike wrote:
I recorded a macro that sorts data in a certiain way, however sometimes the
data is 100 rows and sometimes it's more or less. How can I record the macro
to go to the very last row with printable material within a certain column
regardless of how many rows there are? Or is there a quick way to adjust the
step in of the macro and re-program it there? Any help is greatly
appreciated.
Thanks