Using VB code to copy formulae

Solved/Closed
nephilim3uk Posts 11 Registration date Monday 9 August 2010 Status Member Last seen 27 October 2010 - 11 Oct 2010 à 03:44
aquarelle Posts 7181 Registration date Saturday 7 April 2007 Status Moderator Last seen 14 February 2026 - 13 Oct 2010 à 12:32
Hi

I am using the following code to insert 'x' number of new rows dependant on value 'y' and it does this just how I want, however, I also want the formulae and conditional formating from the original row to be present in all of the new rows because at the moment only the regular formatting is copied.

Any help is greatly appreciated.



Private Sub Worksheet_Change(ByVal Target As Range)
Dim Lst As Long
Dim Rw As Long

' limit to column D
If Intersect(Target, Columns("D")) Is Nothing Then Exit Sub

Application.EnableEvents = False
On Error Resume Next

Lst = Range("D" & Rows.Count).End(xlUp).Row
'For Rw = Lst To 1 Step -1
' With Range("D" & Rw)
With Range("D" & Lst)
.Offset(1).EntireRow.Resize(.Value - 1).Insert
.Offset(1, 1).Resize(.Value - 1) = .Offset(, 1).Value
End With
'Next Rw

On Error GoTo 0
Application.EnableEvents = True

End Sub


1 response

nephilim3uk Posts 11 Registration date Monday 9 August 2010 Status Member Last seen 27 October 2010 1
13 Oct 2010 à 12:23
solved it.....
added the following line to the code;

.entirerow.copy .Offset(1).entirerow.Resize(.Value-1)
aquarelle Posts 7181 Registration date Saturday 7 April 2007 Status Moderator Last seen 14 February 2026 491
13 Oct 2010 à 12:32
Hi,

Thanks for having shared your solution with us.

Best regards :)