Macro Insert Headers after sorting
Closed
geekboy101
Posts
3
Registration date
Monday June 24, 2013
Status
Member
Last seen
June 27, 2013
-
Jun 24, 2013 at 03:26 PM
venkat1926 Posts 1863 Registration date Sunday June 14, 2009 Status Contributor Last seen August 7, 2021 - Jun 28, 2013 at 08:34 AM
venkat1926 Posts 1863 Registration date Sunday June 14, 2009 Status Contributor Last seen August 7, 2021 - Jun 28, 2013 at 08:34 AM
Related:
- Macro Insert Headers after sorting
- Insert check mark in word - Guide
- How to insert photo in word for resume - Guide
- Insert draft watermark in word on all pages - Guide
- Insert key on laptop - Guide
- Insert gif in excel - Guide
3 responses
venkat1926
Posts
1863
Registration date
Sunday June 14, 2009
Status
Contributor
Last seen
August 7, 2021
811
Jun 25, 2013 at 02:41 AM
Jun 25, 2013 at 02:41 AM
copy the data in SHEET2 FROM a!
run this macro . the result is in SHEET1
run this macro . the result is in SHEET1
Sub test() Dim r As Range, c As Range, rd As Range 'undoing Worksheets("sheet1").Cells.Clear Worksheets("sheet2").Cells.Copy Worksheets("sheet1").Range("A1") 'start exercise Worksheets("sheet1").Activate Set r = Range("A1").CurrentRegion r.Sort key1:=Range("D1"), order1:=xlDescending, Header:=xlYes Set rd = Range(Range("D2"), Range("D2").End(xlDown)) For Each c In rd 'MsgBox c.Row If c < 0 Then Range(c, c.Offset(1, 0)).EntireRow.Insert Range(Range("A1"), Range("A1").End(xlToRight)).Copy Cells(c.Row - 1, "A") GoTo outofit End If Next c outofit: Set r = Range("a1").CurrentRegion ' MsgBox r.Address r.Sort key1:=Range("B1"), Header:=xlYes Set r = Range("a1").End(xlDown).Offset(2, 0) Set rd = r.CurrentRegion ' MsgBox rd.Address rd.Sort key1:=Columns(2), order1:=xlAscending, Header:=xlYes MsgBox "macro over" End Sub
venkat1926
Posts
1863
Registration date
Sunday June 14, 2009
Status
Contributor
Last seen
August 7, 2021
811
Jun 25, 2013 at 10:45 PM
Jun 25, 2013 at 10:45 PM
see the result of my macro - you canfind here. comment o this
http://speedy.sh/AjXWh/geek.xlsm
http://speedy.sh/AjXWh/geek.xlsm
geekboy101
Posts
3
Registration date
Monday June 24, 2013
Status
Member
Last seen
June 27, 2013
Jun 27, 2013 at 02:15 PM
Jun 27, 2013 at 02:15 PM
I downloaded the file and it worked like i described.
It separates the list between positive and negative values under the amount column. But what it fails to do is separate the resulting list between positive and negative values under the days overdue column.
While this is great and I will be able to use this manually, since it splits the credits (amount column).
I still need to manually insert a row between the overdue invoices and current ones. (days overdue column)
It separates the list between positive and negative values under the amount column. But what it fails to do is separate the resulting list between positive and negative values under the days overdue column.
While this is great and I will be able to use this manually, since it splits the credits (amount column).
I still need to manually insert a row between the overdue invoices and current ones. (days overdue column)
venkat1926
Posts
1863
Registration date
Sunday June 14, 2009
Status
Contributor
Last seen
August 7, 2021
811
Jun 28, 2013 at 08:34 AM
Jun 28, 2013 at 08:34 AM
added a macro testtwo and incorporated in test. enough to run onl;y TEST.
Sub test() 'undoing Worksheets("sheet1").Cells.Clear Worksheets("sheet2").Cells.Copy Worksheets("sheet1").Range("A1") 'start exercise Worksheets("sheet1").Activate Set r = Range("A1").CurrentRegion r.Sort key1:=Range("D1"), order1:=xlDescending, Header:=xlYes Set rd = Range(Range("D2"), Range("D2").End(xlDown)) For Each c In rd 'MsgBox c.Row If c < 0 Then Range(c, c.Offset(1, 0)).EntireRow.Insert Range(Range("A1"), Range("A1").End(xlToRight)).Copy Cells(c.Row - 1, "A") GoTo outofit End If Next c outofit: Set r = Range("a1").CurrentRegion ' MsgBox r.Address r.Sort key1:=Range("B1"), Header:=xlYes Set r = Range("a1").End(xlDown).Offset(2, 0) Set rd = r.CurrentRegion ' MsgBox rd.Address rd.Sort key1:=Columns(2), order1:=xlAscending, Header:=xlYes testtwo MsgBox "macro over" End Sub
Sub testtwo() Dim llastcell As Range Set r = Range("A1").CurrentRegion r.Sort key1:=Range("c1"), order1:=xlAscending, Header:=xlYes Set r = Range(Range("c2"), Range("c2").End(xlDown)) For Each c In r If c >= 0 Then Range(c, c.Offset(1, 0)).EntireRow.Insert GoTo nnext End If Next c nnext: Range(Range("a1"), Range("a1").End(xlToRight)).Copy Range("a1").End(xlDown).Offset(2, 0) End Sub
Jun 25, 2013 at 05:01 PM
It works well, but is not quite what is needed. The result should be 3 tables.
- the first table should show only invoices (positive amounts) that is more than 0, under days overdue. (Sorted by oldest to newest).
- the second table should contain invoices (positive amounts) that is less than 0 in the days overdue column
- the 3rd table, which you're code is already able to do, contains credits or items with negative balue under amount, regardless of days overdue.
It works well that it separates the positive amounts from the negative amounts under the "Amounts" column, and inserts a header in between. Your code results in 2 tables, the 1st one containing all positive items or invoices, the 2nd table, containing credits or lines with negative value under amount. This works great, but if we can take it a step further and sort the 1st table created from your code, and sort it with largest to smallest under days overdue, find the first value less than zero under that same column and insert the headers there.