I'm attempting create a macro that will add a new line below the line in which the user is, copies all data and formulas from the line above, except for columns G and H. Ends in Column G, ready for editing. I came up the macro below, which does what I want, if you are in row 3, but how do I generalize it.
Another way to ask the question, how do I change the reference
Rows("4:4").Select
to something that means select the row below the one I'm in. e.g.
Rows("the-one-I'm-in+1").Select
Any help appreciated.Sub AddSecondProduct() ' ' AddSecondProduct Macro ' Rows("4:4").Select Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove Rows("3:3").Select Selection.Copy Rows("4:4").Select ActiveSheet.Paste Range("G4:H4").Select Application.CutCopyMode = False Selection.ClearContents Range("G4").Select End Sub
JensPeter
Last edited by davesexcel; 10-27-2010 at 12:03 AM.
Maybe activecell would work, here is an example using activecell
select a cell in column a and run the code
ActiveCell.Range("A1:F1").Copy ActiveCell.Range("A1:E1").Insert Shift:=xlDown ActiveCell.Offset(1, 0).Range("A1").PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _ SkipBlanks:=False, Transpose:=False ActiveCell.Range("G1").Select Application.CutCopyMode = False
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks