Sort by Group Header or by Group SubHeader

A

Aria

Hello,
I'm perplexed on how to go about solving a Sorting problem in code. I
have a group of rows with data listed across the columns ie.

Row 3, Employee Name, [Name Input], Sales Yr, Jan, Feb, Mar,
...etc,Total.
Row 4, Employee Number, [Number Input], Sales Yr, Jan, Feb, Mar, ...etc,
Total.
Row 5, Employee Status, [Status Input], Sales Yr, Jan, Feb, Mar, ...etc,
Total.
Row 6, Other Info, [Info Input], Sales Yr, Jan, Feb, Mar, ...etc, Total.

This segment of data gets repeated down the sheet for each employee. Is
there a way to sort by choosing the [Name Input] or by [Number Input]
and keep each segment together?

Thanks so much,
Aria :)
 
G

Guest

You can try something like this. This code swaps to ranges of cells.

Sub sortRange()

myend = 100

For I = 0 To (myend - 1)
For j = (I + 1) To myend


Set FirstRange = _
Range("A1:p4").Offset(Rowoffset:=4 * I, columnoffset:=0)
Set SecondRange = _
Range("A1:p4").Offset(Rowoffset:=4 * (j + 1), columnoffset:=0)


FirstRange.Select
FirstRange.Cut
SecondRange.Select
SecondRange.Insert (xlShiftDown)

If (I + 1 <> j) Then

Set FirstRange = _
Range("A1:p4").Offset(Rowoffset:=4 * I, columnoffset:=0)
Set SecondRange = _
Range("A1:p4").Offset(Rowoffset:=4 * (j - 1), columnoffset:=0)
End If


FirstRange.Select
FirstRange.Cut
SecondRange.Select
SecondRange.Insert (xlShiftDown)

Next j
Next I

End Sub
 
A

Aria

Hi Joel,
I've tried your suggestion and it kept on looping/running. It's my
spreadsheet because I have about 17 rows (varies) of data per employee.
So could you help me please, tweak your code so that it would recognize
Employee Name title within Column A down to the next Employee Name
title, and up 1 row as the entire segment to move/resort?

The sort criteria is the Employee Name Input cell which is 1 column to
the right of Employee Name title.

Your help is greatly appreciated.

Thanks,
Aria :)
 
G

Guest

Aria said:
Hello,
I'm perplexed on how to go about solving a Sorting problem in code. I
have a group of rows with data listed across the columns ie.

Row 3, Employee Name, [Name Input], Sales Yr, Jan, Feb, Mar,
...etc,Total.
Row 4, Employee Number, [Number Input], Sales Yr, Jan, Feb, Mar, ...etc,
Total.
Row 5, Employee Status, [Status Input], Sales Yr, Jan, Feb, Mar, ...etc,
Total.
Row 6, Other Info, [Info Input], Sales Yr, Jan, Feb, Mar, ...etc, Total.

This segment of data gets repeated down the sheet for each employee. Is
there a way to sort by choosing the [Name Input] or by [Number Input]
and keep each segment together?

Thanks so much,
Aria :)
 

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