Autorun VB Code

[Closed]
Report
Posts
11
Registration date
Monday August 9, 2010
Status
Member
Last seen
October 27, 2010
-
Posts
1864
Registration date
Sunday June 14, 2009
Status
Contributor
Last seen
August 7, 2021
-
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

Posts
1864
Registration date
Sunday June 14, 2009
Status
Contributor
Last seen
August 7, 2021
803
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
Thank you

A few words of thanks would be greatly appreciated. Add comment

CCM 2821 users have said thank you to us this month