The part of the code giving me the error is borrowed from research on how to find a specific value, match it to a value on another worksheet and delete that row of data. The code has multi tasks to complete:
Copy the row on sheet22 and paste it to the next empty row on sheet13
Find a match to Sheet22 cell C2 on Sheet 11 column A and delete the matching row on sheet 11
Add formulas into columns F:M & Q on row 2 of sheet22
Sub LineArchive_DD118() Dim TMLastDistRow Dim Answer As VbMsgBoxResult Dim LastRowInRange As Long, RowCounter As Long TMLastDistRow = Worksheets("Trailer Archives").Cells(Sheet13.Rows.Count, "B").End(xlUp).Row + 1 LastRowInRange = Sheets(Sheet11).Range("A:A").Find("*", , xlFormulas, , xlByRows, xlPrevious).Row ' Returns a Row Number Application.ScreenUpdating = False Application.EnableEvents = False If Sheets("Dock Door Status").Range("P2").Value = "F" Then With Sheets("Dock Door Status") .Range("P2").Value = "F" .Range("C2:R2").Copy End With With Sheets("Trailer Archives") .Range("B" & TMLastDistRow).PasteSpecial Paste:=xlPasteValues End With Else Exit Sub End If Answer = MsgBox("Are you sure you want to clear DD118?", vbYesNo + vbCritical + vbDefaultButton2, "Dock Door 118 Data") If Answer = vbYes Then For RowCounter = LastRowInRange To 1 Step -1 ' Count Backwards If Sheets("Sheet11").Range("A" & RowCounter) = Sheets("Sheet22").Range("C2") Then ' If Cell matches our 'Delete if' value then Sheets("Sheet11").Rows(RowCounter).EntireRow.Delete ' Delete the row End If Next With Sheets("Dock Door Status") .Range("D2:Q2").ClearContents .Range("D2") = "CLOSED" End With With Sheets("Dock Door Status") .Range("F2").Formula = "=IFERROR(INDEX('SSP Data'!B$2:B$50,MATCH($C2,'SSP Data'!$A$2:$A$50,0)),"""")" .Range("G2").Formula = "=IFERROR(INDEX('SSP Data'!C$2:C$50,MATCH($C2,'SSP Data'!$A$2:$A$50,0)),"""")" .Range("H2").Formula = "=IFERROR(INDEX('SSP Data'!D$2:D$50,MATCH($C2,'SSP Data'!$A$2:$A$50,0)),"""")" .Range("I2").Formula = "=IFERROR(INDEX('SSP Data'!E$2:E$50,MATCH($C2,'SSP Data'!$A$2:$A$50,0)),"""")" .Range("J2").Formula = "=IFERROR(INDEX('SSP Data'!F$2:F$50,MATCH($C2,'SSP Data'!$A$2:$A$50,0)),"""")" .Range("K2").Formula = "=IFERROR(INDEX('SSP Data'!G$2:G$50,MATCH($C2,'SSP Data'!$A$2:$A$50,0)),"""")" .Range("L2").Formula = "=IFERROR(INDEX('SSP Data'!H$2:H$50,MATCH($C2,'SSP Data'!$A$2:$A$50,0)),"""")" .Range("M2").Formula = "=IFERROR(INDEX('SSP Data'!I$2:I$50,MATCH($C2,'SSP Data'!$A$2:$A$50,0)),"""")" .Range("Q2").Formula = "=IF(G2="""","""",IF(AND(M2="""",N2>G2),""Future"",""Current""))" End With Else Exit Sub End If Application.EnableEvents = True Application.ScreenUpdating = True End Sub
The line that is throwing the error is:
LastRowInRange = Sheets(Sheet11).Range("A:A").Find("*", , xlFormulas, , xlByRows, xlPrevious).Row ' Returns a Row Number
I think that part of it is I would like to replace the wildcard with a static text string, i.e. "*" with "DD118". I am sure there is more to the error than that.
All help is appreciated.