|
| Computing.Net: Over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to sign up now, it's free! |
VBA - Insert Row(s), Copy 1 Cell
|
Original Message
|
Name: 24HG_Hoop
Date: May 18, 2008 at 09:42:05 Pacific
Subject: VBA - Insert Row(s), Copy 1 CellOS: XP ProCPU/Ram: 2800 / 2GModel/Manufacturer: clone |
Comment: Hi all, I've got the following macro, which I use in another project, to insert N rows and copy three formulas in F9:H9. The macro I have copies down each formula into cells F10:F400, G10:G400, etc.. In a new project, I want to do a similar thing, except I only want one formula [a max()+1 formula in J2] and copy the cell contents (NOT the formula!) into the J column of my new row. Anywho... here's the original macros. Only the last line would need changing. Sub InsertRow() Dim Rng, n As Long, k As Long Application.ScreenUpdating = False Rng = InputBox("Enter number of rows required.") If Rng = "" Then Exit Sub Range(ActiveCell, ActiveCell.Offset(Val(Rng) - 1, 0)).EntireRow.Insert k = ActiveCell.Offset(-1, 0).Row n = Cells(k, 2).End(xlToLeft).Column Range(Cells(k, 2), Cells(k + Val(Rng), n)).FillDown CopySideFormulaDown
End Sub Sub CopySideFormulaDown() Range("J2").Select.Value Selection.AutoFill Destination:=Range("XXX"), Type:=xlFillDefault Thx
Report Offensive Message For Removal
|
|
Response Number 1
|
Name: Razor2.3
Date: May 18, 2008 at 14:46:22 Pacific
|
Reply: (edit)You want to copy the value, and not the formula? That's easy enough. Instead of Range("J2").Select.Value Selection.AutoFill Destination:=Range("XXX"), Type:=xlFillDefault use Range("XXX").Formula = Range("J2").Value
Report Offensive Follow Up For Removal
|
|
Response Number 2
|
Name: 24HG_Hoop
Date: May 18, 2008 at 15:40:00 Pacific
|
Reply: (edit)Not exactly, Razor I want the value in J2 to drop into column J of the NEW row I just created with the InsertRow macro. Taking from what you said, I've corrected it below, but that still doesn't tell it to place the contents of J2 into J[New] (or J[New+1], J[New+2], etc. for an answer of >=2 in the InputBoxq question.
Report Offensive Follow Up For Removal
|
|
Response Number 3
|
Name: 24HG_Hoop
Date: May 18, 2008 at 15:43:43 Pacific
|
Reply: (edit)Sorry - failed to post revised statements Selection.AutoFill Destination:=Range("J2").Value, Type:=xlFillDefault To rephrase - what ^^^ not just fill ALL cells in the new row(s)? Or, would it just copy J?
Report Offensive Follow Up For Removal
|
|
Response Number 4
|
Name: 24HG_Hoop
Date: May 18, 2008 at 17:11:09 Pacific
|
Reply: (edit)Fixed it. Thx for your help, Razor. Here's the code, FYI
Sub InsertRowCopyJ2intoJCol() Dim Rng, n As Long, k As Long Application.ScreenUpdating = False Rng = 1 If Rng = "" Then Exit Sub Range(ActiveCell, ActiveCell.Offset(0, 0)).EntireRow.Insert k = ActiveCell.Offset(0, 0).Row n = Cells(k, 10).End(xlToLeft).Column Range(Cells(k, 10), Cells(k + Val(Rng) - 1, 10)).Formula = Range("J2").Value I took away the option of multiple rows being inserted, and the whole InputBox, but ... That'll do pig, that'll do... End Sub
Report Offensive Follow Up For Removal
|

Post Locked
This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
Go to Programming Forum Home
|
|
|