Autorun VB Code

Closed
nephilim3uk
Posts
11
Registration date
Monday August 9, 2010
Status
Member
Last seen
October 27, 2010
- Aug 13, 2010 at 04:31 PM
venkat1926
Posts
1864
Registration date
Sunday June 14, 2009
Status
Contributor
Last seen
August 7, 2021
- Aug 13, 2010 at 10:00 PM
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 reply

venkat1926
Posts
1864
Registration date
Sunday June 14, 2009
Status
Contributor
Last seen
August 7, 2021
808
Aug 13, 2010 at 10:00 PM
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.
1