Sort by Group Header or by Group SubHeader
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 :) *** Sent via Developersdex http://www.developersdex.com *** |
Sort by Group Header or by Group SubHeader
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 "Aria" wrote: 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 :) *** Sent via Developersdex http://www.developersdex.com *** |
Sort by Group Header or by Group SubHeader
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 :) *** Sent via Developersdex http://www.developersdex.com *** |
Sort by Group Header or by Group SubHeader
"Aria" wrote: 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 :) *** Sent via Developersdex http://www.developersdex.com *** |
Sort by Group Header or by Group SubHeader
Any help would be greatly appreciated.
Aria :) *** Sent via Developersdex http://www.developersdex.com *** |
All times are GMT +1. The time now is 06:37 PM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com