Sorting question-is this possible

J

JOUIOUI

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?
 
D

Dave Unger

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top