Run macro when adding a new line
Thank you. This does more or less work, but,
Is there any way
a) to avoid inserting code in the worksheet [in case I need to add another
sheet I would need to add as well the code]
b) to run the macro not at the action following the insertion but just after
the insertion occurs
?
"Gary''s Student" wrote:
To trap inserting a row or adding a row to the bottom of a worksheet, in a
standard module insert:
Public linez As Long
Sub init()
linez = 1
End Sub
and then run init
In Wroksheet code insert:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim nLastRow As Long, r As Range
Set r = ActiveSheet.UsedRange
nLastRow = r.Rows.Count + r.Row - 1
If nLastRow = linez Then
Else
MsgBox ("got bigger")
linez = nLastRow
End If
End Sub
The first time any cell is select, the trap snaps. From then on the trap
will sanp whenever row are added.
--
Gary's Student
"S. G." wrote:
Is there any way to intercept the built-in order for new line and run a macro
whenever it is executed?
|