unknownymous
Board Regular
- Joined
- Sep 19, 2017
- Messages
- 249
- Office Version
- 2016
- Platform
- Windows
Hi Guys,
Can you possibly help me clean up below codes? The range of cells with data is from A:AD
1. Basically starting in AG5, I will create a sum formula from E5:T5 which will be copied down to the last non blank cell (not just till range 681).
2. The macro will hardcode the sum column and sort by descending.
3. If the sum total is zero it will create a separator by adding a row.
4. Afterwards, delete the sum column
Draft codes:
----------------------
Sub Macrotest()
ActiveCell.FormulaR1C1 = "=SUM(RC[-28]:RC[-13])"
Range("AG5").Select
Selection.Copy
ActiveWindow.SmallScroll Down:=-12
Range("AG5:AG681").Select
ActiveSheet.Paste
Rows("5:681").Select
Range("AG5").Activate
Application.CutCopyMode = False
ActiveWorkbook.Worksheets("Macro Sheet").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Macro Sheet").Sort.SortFields.Add Key:=Range( _
"AG5:AG681"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("Macro Sheet").Sort
.SetRange Range("A5:AG681")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Columns("AG:AG").Select
Range("AG26").Activate
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Selection.End(xlUp).Select
End Sub
----------------------------------
Example Output (separate those with zero as total):
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]QTY[/TD]
[/TR]
[TR]
[TD]500[/TD]
[/TR]
[TR]
[TD]100[/TD]
[/TR]
[TR]
[TD]50[/TD]
[/TR]
[TR]
[TD]20[/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD]0[/TD]
[/TR]
[TR]
[TD]0[/TD]
[/TR]
</tbody>[/TABLE]
Any help will be much appreciated
Thank you!
Can you possibly help me clean up below codes? The range of cells with data is from A:AD
1. Basically starting in AG5, I will create a sum formula from E5:T5 which will be copied down to the last non blank cell (not just till range 681).
2. The macro will hardcode the sum column and sort by descending.
3. If the sum total is zero it will create a separator by adding a row.
4. Afterwards, delete the sum column
Draft codes:
----------------------
Sub Macrotest()
ActiveCell.FormulaR1C1 = "=SUM(RC[-28]:RC[-13])"
Range("AG5").Select
Selection.Copy
ActiveWindow.SmallScroll Down:=-12
Range("AG5:AG681").Select
ActiveSheet.Paste
Rows("5:681").Select
Range("AG5").Activate
Application.CutCopyMode = False
ActiveWorkbook.Worksheets("Macro Sheet").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Macro Sheet").Sort.SortFields.Add Key:=Range( _
"AG5:AG681"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("Macro Sheet").Sort
.SetRange Range("A5:AG681")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Columns("AG:AG").Select
Range("AG26").Activate
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Selection.End(xlUp).Select
End Sub
----------------------------------
Example Output (separate those with zero as total):
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]QTY[/TD]
[/TR]
[TR]
[TD]500[/TD]
[/TR]
[TR]
[TD]100[/TD]
[/TR]
[TR]
[TD]50[/TD]
[/TR]
[TR]
[TD]20[/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD]0[/TD]
[/TR]
[TR]
[TD]0[/TD]
[/TR]
</tbody>[/TABLE]
Any help will be much appreciated
Thank you!