Autorun VB Code

Closed
nephilim3uk Posts 11 Registration date Monday 9 August 2010 Status Member Last seen 27 October 2010 - 13 Aug 2010 à 16:31
venkat1926 Posts 1863 Registration date Sunday 14 June 2009 Status Contributor Last seen 7 August 2021 - 13 Aug 2010 à 22:00
Hello,

As a newbie some further help would be appreciated;
I have some VB code in module 1 that automatically inserts 'x' number of rows depending on value 'y'. What I could really do with having is a way of the code automatically running when a value is input in a given cell eg any row in column D.

The code for inserting new rows that I have used is;
[Code]
Sub ()
Dim Lst As Long
Dim Rw As Long
On Error Resume Next

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

any help is really apreciated

thanks

Richard


1 response

venkat1926 Posts 1863 Registration date Sunday 14 June 2009 Status Contributor Last seen 7 August 2021 811
13 Aug 2010 à 22:00
right click the sheet tab and click view code.
in that window copy this event code

============
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column <> 4 Then Exit Sub
<name of the macro>
End Sub
===============

whenever you enter any entry in any cell in D and hit enter key the macro will be run.