In this spreadsheet there are over 4000 rows. I wish to have a macro that will insert a copy of any row just one row beneath a selected row.
I have generated copy macros using both and Absolute and Relative Reference methods but neither does what I want it to do. ( See examples below ). Both work the first time but not afterwards
If I use Absolute references it will only work on the same row as the original ( obviously??).
If I use Relative references it will work on the selected row plus the off-set of the original selected row.
I attach an example based on eight lines from the spreadsheet..
Example 1 is the original.
Account No Product No Goods Value Tax Total inc Tax Date Shipped Invoice Number Date Invoiced Payment Value Payment Date Notes
20124 47AB16 120.12 21.02 141.14 11-Jan-07 CL0159 11-Jan-07 141.14 14-Feb-07
20125 54DE01 23.00 4.03 27.03 20-Jan-07 CL0160 20-Jan-07 27.03 30-Jan-07
20130 47AB16 120.12 21.02 141.14 20-Jan-07 CL0165 20-Jan-07 100.00 14-Feb-07 41.14 O/S
20132 47AB16 120.12 21.02 141.14 30-Jan-07 CL0170 30-Jan-07 141.14 22-Feb-07
20133 63KT21 213.00 37.28 250.28 14-Feb-07 CL0171 14-Feb-07 250.28 10-Mar-07
20133 47AB16 120.12 21.02 141.14 14-Feb-07 CL0171 14-Feb-07
20134 14AA23 15.50 2.71 18.21 28-Feb-07 CL0180 28-Feb-07 18.21 20-Mar-07
Example two is what I wish to achieve. That is:_
Copy an existing Row ( Row 4 in the example )
Insert and Paste the Copy of the original row in the next line down.
( Copy of Row 4 inserted as new Row 5,
Original Rows 5 and others pushed down one )
Insert new Blank row into Row 6. Original Rows 5 and others pushed down one )
Copy Account Number from original Row 4 and paste in column A of new Row 6
Write "Con Sol" or some other text into Column B of new Row
End of Macro.
Then add further info on the added line.
Here is what I am trying to achieve as Example 2.
Account No Product No Goods Value Tax Total inc Tax Date Shipped Invoice Number Date Invoiced Payment Value Payment Date Notes
20124 47AB16 120.12 21.02 141.14 11-Jan-07 CL0159 11-Jan-07 141.14 14-Feb-07
20125 54DE01 23.00 4.03 27.03 20-Jan-07 CL0160 20-Jan-07 27.03 30-Jan-07
20130 47AB16 120.12 21.02 141.14 20-Jan-07 CL0165 20-Jan-07 100.00 14-Feb-07 41.14 O/S
20130 47AB16 120.12 21.02 141.14 20-Jan-07 CL0165 20-Jan-07 100.00 14-Feb-07 41.14 O/S
20130 Con Sol Add further info
20132 47AB16 120.12 21.02 141.14 30-Jan-07 CL0170 30-Jan-07 141.14 22-Feb-07
20133 63KT21 213.00 37.28 250.28 14-Feb-07 CL0171 14-Feb-07 250.28 10-Mar-07
20133 47AB16 120.12 21.02 141.14 14-Feb-07 CL0171 14-Feb-07
20134 14AA23 15.50 2.71 18.21 28-Feb-07 CL0180 28-Feb-07 18.21 20-Mar-07
I have been trying to "automate" this for months.
Can any one advise on how to achieve this please?
Here are copies of the two attempted macros.
Example 1
Sub Macro3()
'
' Macro3 Macro
' Macro recorded 21/08/2007 by Wej 3
'
' Keyboard Shortcut: Ctrl+p
' Using Relative addressing ????
'
'
ActiveCell.Offset(-4, 0).Rows("1:1").EntireRow.Select
Selection.Copy
ActiveCell.Rows("1:1").EntireRow.Select
Selection.Insert Shift:=xlDown
ActiveCell.Offset(2, 0).Rows("1:1").EntireRow.Select
Application.CutCopyMode = False
Selection.Insert Shift:=xlDown
ActiveCell.Offset(-1, 0).Range("A1").Select
Selection.Copy
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveSheet.Paste
ActiveCell.Offset(0, 10).Range("A1").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "Relative"
ActiveCell.Offset(5, -10).Range("A1").Select
End Sub
Example 2
Sub Macro4()
'
' Macro4 Macro
' Macro recorded 21/08/2007 by Reservations 3
'
' Keyboard Shortcut: Ctrl+o
'
' Using Absolute addressing ????
'
Rows("3:3").RowHeight = 13.5
Rows("4:4").Select
Selection.Copy
Rows("5:5").Select
Selection.Insert Shift:=xlDown
Rows("6:6").Select
Application.CutCopyMode = False
Selection.Insert Shift:=xlDown
Range("A5").Select
Selection.Copy
Range("A6").Select
ActiveSheet.Paste
Range("K6").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "Non-Relative"
Range("A11").Select
End Sub
End of message
Bookmarks