In the attached example - I need to be able to do the following:
If Name on MemoryImport sheet does not match Name on Memory sheet then copy the unmatched Name from the MemoryImport sheet to the Memory sheet inserting row or rows starting at row 4 and inserting the unmatched Name into column A. The other rows on the Memory tab have formulas and will need to retain the cell references for those also.
If I understood you right, perhaps this is what you want..
Sub CopyUnmatchedHostNames() Dim wsMemoryImport As Worksheet Dim wsMemory As Worksheet Dim rCheck As Range Dim rCell As Range Dim iCheck As Long Dim iCnt As Long Set wsMemoryImport = ThisWorkbook.Worksheets("MemoryImport") Set wsMemory = ThisWorkbook.Worksheets("Memory") With wsMemoryImport Set rCheck = .Range("A4", .Cells(.Rows.Count, 1).End(xlUp)) End With For Each rCell In rCheck.Cells On Error GoTo NoMatch iCheck = 0 iCheck = WorksheetFunction.Match(rCell.Value, wsMemory.Range("D:D"), 0) GoTo MatchFoundNoMatch: On Error Resume Next wsMemory.Rows(4).Copy wsMemory.Rows(4).Insert wsMemory.Range("A4:C4").ClearContents wsMemory.Range("D4").Value = rCell.Value iCnt = iCnt + 1MatchFound: On Error GoTo 0 Next rCell If iCnt > 0 Then MsgBox iCnt & " total record(s) were copied.", vbExclamation, "DONE!" Else MsgBox "No Host Names copied.", vbExclamation, "DONE!" End IfEnd Sub
This will go through the MemoryImport sheet looking at the Host Name (col A) looking for matches in the Memory sheet in column D (Host Name). If any values are not found in the Memory sheet it will insert a row at row 4, clear cols A through C of that row and populate D4 with the Host Name. There is a message box telling you how many were copied, if at all.
Microsoft Excel topics include formulas, formatting, VBA macros and user-defined functions, and everything else related to the spreadsheet user interface, including error messages.
If I understood you right, perhaps this is what you want..
Open in new window
This will go through the MemoryImport sheet looking at the Host Name (col A) looking for matches in the Memory sheet in column D (Host Name). If any values are not found in the Memory sheet it will insert a row at row 4, clear cols A through C of that row and populate D4 with the Host Name. There is a message box telling you how many were copied, if at all.
HTH
Regards,
Zack Barresse