Hello RAH,
The macro is attached to the worksheet to the by its Worksheet_Change event procedure. Whenever a cell's value is changed, the macro runs. I have made a change to blank the quantity when the line is copied. The change is marked in blue.
Private Sub Worksheet_Change(ByVal Target As Range)
Dim LastCol As Long
Dim R As Long
Dim vt As Long
On Error Resume Next
vt = Target.Validation.Type
If Err.Number = 1004 Then
Err.Clear
End If
On Error GoTo 0
Application.EnableEvents = False
R = Target.Row
With ActiveSheet.UsedRange
LastCol = .Columns.Count + .Column - 1
End With
If vt = xlValidateList And Cells(R, "A") = "Add a Line" Then
Target.Offset(1, 0).EntireRow.Insert Shift:=xlDown
Range(Cells(R, "B"), Cells(R + 1, LastCol)).FillDown
Cells(R, "C").Value = ""
End If
Application.EnableEvents = True
End Sub
How to Save a Worksheet Event Macro
1. Copy the macro using CTRL+C keys.
2. Open your Workbook and Right Click on the Worksheet's Name Tab for the Worksheet the macro will run on.
3. Left Click on View Code in the pop up menu.
4. Paste the macro code using CTRL+V
5. Save the macro in your Workbook using CTRL+S
Sincerely,
Leith ross
Bookmarks