ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Sorting question-is this possible (https://www.excelbanter.com/excel-programming/384628-sorting-question-possible.html)

JOUIOUI

Sorting question-is this possible
 
I would like to write code sorting the entire spreadsheet, excluding headers,
by first sorting column I to put all topics together in descending order and
then adding an empty row at the end of each topic to separate them. My
topics are just 3 values and they are

Stationary
Posters
Books

Then my next sort is to isolate each topic and sort each topic individually
by column D ascending. Col D is a currency value.

The end result would be each topic in column I would be sorted by ascending
dollar value in Col D

This spreadsheet is updated each day so the row count is unknown. Is this
even possible?


Dave Unger

Sorting question-is this possible
 
Hi Jouioui,

This might be one way to do it. I've done limited testing, but it
seems to work Ok.

Just add your updated rows at the bottom of the list then run this
macro.

Sub SrtCat()

Dim rng As Range, x As Integer

Set rng = ActiveSheet.UsedRange

rng.Sort Key1:=Range("A1"), Order1:=xlAscending, Key2:=Range("D1")
_
, Order2:=xlAscending, Header:=xlYes, OrderCustom:=1,
MatchCase:= _
False, Orientation:=xlTopToBottom

Set rng = Range(Cells(1, 1), Cells(Rows.Count, 1).End(xlUp))

For x = rng.Count To 3 Step -1
'rng(x).Select
If rng(x) < rng(x - 1) Then rng(x).EntireRow.Insert
(xlShiftDown)
Next x
End Sub

regards,

DaveU


On Mar 6, 9:36 am, JOUIOUI wrote:
I would like to write code sorting the entire spreadsheet, excluding headers,
by first sorting column I to put all topics together in descending order and
then adding an empty row at the end of each topic to separate them. My
topics are just 3 values and they are

Stationary
Posters
Books

Then my next sort is to isolate each topic and sort each topic individually
by column D ascending. Col D is a currency value.

The end result would be each topic in column I would be sorted by ascending
dollar value in Col D

This spreadsheet is updated each day so the row count is unknown. Is this
even possible?





All times are GMT +1. The time now is 10:53 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com