Computing.Net > Forums > Programming > VBA - Insert Row(s), Copy 1 Cell

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

VBA - Insert Row(s), Copy 1 Cell

Reply to Message Icon

Name: 24HG_Hoop
Date: May 18, 2008 at 09:42:05 Pacific
OS: XP Pro
CPU/Ram: 2800 / 2G
Product: 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



Sponsored Link
Ads by Google

Response Number 1
Name: Razor2.3
Date: May 18, 2008 at 14:46:22 Pacific
Reply:

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


0

Response Number 2
Name: 24HG_Hoop
Date: May 18, 2008 at 15:40:00 Pacific
Reply:

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.


0

Response Number 3
Name: 24HG_Hoop
Date: May 18, 2008 at 15:43:43 Pacific
Reply:

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?


0

Response Number 4
Name: 24HG_Hoop
Date: May 18, 2008 at 17:11:09 Pacific
Reply:

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


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







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


Sponsored links

Ads by Google


Results for: VBA - Insert Row(s), Copy 1 Cell

to select row(s) in JTable www.computing.net/answers/programming/to-select-rows-in-jtable/5969.html

VBA XL insert row & move image alng www.computing.net/answers/programming/vba-xl-insert-row-move-image-alng/17193.html

Insert a specific row at ActiveCell www.computing.net/answers/programming/insert-a-specific-row-at-activecell/17078.html