I have an Excel spreadsheet with two sheets. In sheet1 I have multiple rows each with a dropdown which is used to set the status of the row. If the status gets changed to 'Completed' or 'On Hold' it should get deleted from sheet1 and moved to the next available row in sheet2.
However after it is deleted from sheet1 I get
Run-time error 13 - type mismatch
Below is a screenshot of the highlighted code, link to screen capture of the error, screenshot of sheet1 and the highlighted debug code.
Private Sub Worksheet_Change(ByVal Target As Range)
Dim KeyCells As Range
Set KeyCells = Range("B:B")
If Not Application.Intersect(KeyCells, Range(Target.Address)) _
Is Nothing Then
If (Target.Value = "Complete" Or Target.Value = "On Hold") Then
ActiveCell.EntireRow.Copy
Worksheets("Sheet2").Activate
i = Worksheets("Sheet2").Cells(Rows.Count, 1).End(xlUp).Row
Worksheets("Sheet2").Cells(i + 1, 1).Select
ActiveSheet.Paste
Worksheets("Sheet1").Activate
ActiveCell.EntireRow.Delete
End If
End If
End Sub
Select
andActivate
: How to avoid using Select in Excel VBA. – erazorv4If
statement – Tim Stack