Hi guys,
I have the working code below, however when I try to added to run in a change event the Range with lastrow stops working, wondering if any of you can advice on what can I do?
Sub field_change()
Dim LastRow As Integer
With ActiveSheet
LastRow = .Cells(.Rows.Count, "L").End(xlUp).Row
Range("L" & LastRow).Select
If ActiveCell = "Dev & QA" Then
ActiveCell.Offset(1).EntireRow.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromRightOrAbove
ActiveCell.EntireRow.Copy
ActiveCell.Offset(1).EntireRow.PasteSpecial xlPasteFormats
Application.CutCopyMode = False
With ActiveSheet
LastRow = .Cells(.Rows.Count, "L").End(xlUp).Row
Range("L" & LastRow).Offset(0, 1).Select
ActiveCell.Value = Format(Now, "mm/dd/yyyy")
End With
With ActiveSheet
LastRow = .Cells(.Rows.Count, "M").End(xlUp).Row
Range("M" & LastRow).Offset(0, 1).Select
ActiveCell.Value = Application.UserName
End With
With ActiveSheet
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
Range("A" & LastRow).Select
End With
Else
If ActiveCell = "Production" Then
Range("L" & LastRow).Select
' ' MsgBox "Production"
ActiveCell.EntireRow.Copy
Worksheets("Prod").Select
With ActiveSheet
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
Range("A" & LastRow).Select
ActiveCell.Offset(1).Select
ActiveSheet.Paste
With ActiveSheet
LastRow = .Cells(.Rows.Count, "L").End(xlUp).Row
Range("L" & LastRow).Offset(0, 1).Select
ActiveCell.Value = Format(Now, "mm/dd/yyyy")
End With
With ActiveSheet
LastRow = .Cells(.Rows.Count, "M").End(xlUp).Row
Range("M" & LastRow).Offset(0, 1).Select
ActiveCell.Value = Application.UserName
End With
With ActiveSheet
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
Range("A" & LastRow).Select
End With
End With
End If
End If
End With
End Sub
I have the working code below, however when I try to added to run in a change event the Range with lastrow stops working, wondering if any of you can advice on what can I do?
Sub field_change()
Dim LastRow As Integer
With ActiveSheet
LastRow = .Cells(.Rows.Count, "L").End(xlUp).Row
Range("L" & LastRow).Select
If ActiveCell = "Dev & QA" Then
ActiveCell.Offset(1).EntireRow.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromRightOrAbove
ActiveCell.EntireRow.Copy
ActiveCell.Offset(1).EntireRow.PasteSpecial xlPasteFormats
Application.CutCopyMode = False
With ActiveSheet
LastRow = .Cells(.Rows.Count, "L").End(xlUp).Row
Range("L" & LastRow).Offset(0, 1).Select
ActiveCell.Value = Format(Now, "mm/dd/yyyy")
End With
With ActiveSheet
LastRow = .Cells(.Rows.Count, "M").End(xlUp).Row
Range("M" & LastRow).Offset(0, 1).Select
ActiveCell.Value = Application.UserName
End With
With ActiveSheet
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
Range("A" & LastRow).Select
End With
Else
If ActiveCell = "Production" Then
Range("L" & LastRow).Select
' ' MsgBox "Production"
ActiveCell.EntireRow.Copy
Worksheets("Prod").Select
With ActiveSheet
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
Range("A" & LastRow).Select
ActiveCell.Offset(1).Select
ActiveSheet.Paste
With ActiveSheet
LastRow = .Cells(.Rows.Count, "L").End(xlUp).Row
Range("L" & LastRow).Offset(0, 1).Select
ActiveCell.Value = Format(Now, "mm/dd/yyyy")
End With
With ActiveSheet
LastRow = .Cells(.Rows.Count, "M").End(xlUp).Row
Range("M" & LastRow).Offset(0, 1).Select
ActiveCell.Value = Application.UserName
End With
With ActiveSheet
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
Range("A" & LastRow).Select
End With
End With
End If
End If
End With
End Sub