I am having good (bad) time with Excel vba.
I have two sheets in a workbook- sheet1 and sheet2.
Sheet 1
AccountNo Account Name
110101 Imprest
110102 abs
110104 abs - Call
110105 abc-MANAGED
110109 bda - Dollar
110201 jhk - Dollar
Sheet 2
AccountNo Account Name
110101 Imprest
110102 abs
110103 bas
110104 abs - Call
110105 abc-MANAGED
110109 bda - Dollar
110201 jhk - Dollar
I want to compare row the AccountNo column to find out the new accountNo that has been added to sheet2 but not in sheet1. If the AccountNO is found, I want to insert it into sheet1 and it must be inserted into the best position in sheet1 because the account numbers are arranged serially. Example is the 110103 accountNO, i want to insert the entire row after 110102 account no in sheet1.
Dim rngCell As Range
Dim matchRow
For Each rngCell In Worksheets("Sheet2").Range("A2:A200")
If WorksheetFunction.CountIf(Worksheets("Sheet1").Range("A2:A200"), rngCell) = 0 Then
' Range("K" & Rows.Count).End(xlUp).Offset(1) = rngCell
matchRow = rngCell.Row
Rows(matchRow & ":" & matchRow).Select
rngCell.EntireRow.Copy
Range("K" & Rows.Count).PasteSpecial xlPasteValues
End If
Next
The code seem not to help. only able to identify the new accountNOs.