PDA

View Full Version : Solved: Copy 2 cells with formula.



Pinokkio
07-31-2010, 01:40 PM
This invoice with the macro:


Private Sub Worksheet_Change(ByVal target As Range)
If target.Column <> 2 Then Exit Sub
If target.Value <> "" Then
Rows(target.Row + 1).EntireRow.Insert
End If
End Sub




Cell B20 inserted a line with the macro.
But the two formulas in columns C and D are not copied ?
Is here a solution for?


All help greatly appreciated.

Bob Phillips
07-31-2010, 02:23 PM
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column <> 2 Then Exit Sub
If Target.Value <> "" Then
Me.Rows(Target.Row + 1).EntireRow.Insert
Me.Range("C17").Resize(, 2).Copy
Me.Cells(Target.Row + 1, "C").PasteSpecial Paste:=xlPasteFormulas
End If
End Sub

Pinokkio
08-01-2010, 01:50 AM
Sorry,

but it select 2 cells (C17 & D17)?
and just copy one formule (column D)?

Pinokkio
08-01-2010, 02:16 AM
This does it almost,


Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column <> 2 Then Exit Sub
If Target.Value <> "" Then
Me.Rows(Target.Row + 1).EntireRow.Insert
Me.Range("C17").Resize(, 2).Copy
Me.Cells(Target.Row, "C").PasteSpecial Paste:=xlPasteFormulas
End If
Application.CutCopyMode = False
End Sub

but it select 2 cells (C17 & D17) after running the macro?

Pinokkio
08-01-2010, 02:29 AM
[quote=Pinokkio]

This does it,



Private Sub Worksheet_Change(ByVal Target As Range)
Application.CutCopyMode = False
If Target.Column <> 2 Then Exit Sub
If Target.Value <> "" Then
Me.Rows(Target.Row + 1).EntireRow.Insert
Me.Range("C17").Resize(, 2).Copy
Me.Cells(Target.Row, "C").PasteSpecial Paste:=xlPasteFormulas
End If
ActiveCell.Offset(1, -1).Select
End Sub




Thanks for help.

P.

Pinokkio
08-01-2010, 02:30 AM
This does it,



Private Sub Worksheet_Change(ByVal Target As Range)
Application.CutCopyMode = False
If Target.Column <> 2 Then Exit Sub
If Target.Value <> "" Then
Me.Rows(Target.Row + 1).EntireRow.Insert
Me.Range("C17").Resize(, 2).Copy
Me.Cells(Target.Row, "C").PasteSpecial Paste:=xlPasteFormulas
End If
ActiveCell.Offset(1, -1).Select
End Sub




Thanks for help.

P.[/quote]

Pinokkio
08-01-2010, 02:30 AM
This does it,



Private Sub Worksheet_Change(ByVal Target As Range)
Application.CutCopyMode = False
If Target.Column <> 2 Then Exit Sub
If Target.Value <> "" Then
Me.Rows(Target.Row + 1).EntireRow.Insert
Me.Range("C17").Resize(, 2).Copy
Me.Cells(Target.Row, "C").PasteSpecial Paste:=xlPasteFormulas
End If
ActiveCell.Offset(1, -1).Select
End Sub




Thanks for help.

P.

Pinokkio
08-01-2010, 02:31 AM
This does it,



Private Sub Worksheet_Change(ByVal Target As Range)
Application.CutCopyMode = False
If Target.Column <> 2 Then Exit Sub
If Target.Value <> "" Then
Me.Rows(Target.Row + 1).EntireRow.Insert
Me.Range("C17").Resize(, 2).Copy
Me.Cells(Target.Row, "C").PasteSpecial Paste:=xlPasteFormulas
End If
ActiveCell.Offset(1, -1).Select
End Sub




Thanks for help.

P.

Bob Phillips
08-01-2010, 03:46 AM
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column <> 2 Then Exit Sub
If Target.Value <> "" Then
Me.Rows(Target.Row + 1).EntireRow.Insert
Me.Range("C17").Resize(, 2).Copy
Me.Cells(Target.Row, "C").PasteSpecial Paste:=xlPasteFormulas
End If

Me.Cells(Target.Row + 1, "A").Select

Application.CutCopyMode = False
End Sub

Pinokkio
08-01-2010, 12:52 PM
Thanks xld.

P.