I am needing some help figuring out my issue with the part of my VBA sub. I am new to this forum so if I did anything incorrect, please let me know.
Sheet1 is a continuous list of everything being recorded and kept. Sheet2 is an updated list that is retrieved, with updated lines and new lines. Within the lists in column A is a unique ID for every entry in numeric value. What is trying to attempt in the VBA below is to go through every unique ID in sheet2, look for a match in sheet1, replace that entire row values with the new values from sheet2 if there is a match, if there is no match it needs to be placed in the last blank row (+1from xlUp). I have tried other ways that are not below like using scripting.dictionary, but I am not successful so far.
The way I am trying to do this is resulting in my every cell that the “for” is looking at to be true for the if not equal. I’m just not able to figure out how to get around this and not have every item posted multiple time below xlUp. Any help is welcomed as I am new to this forum.
Sheet1 is a continuous list of everything being recorded and kept. Sheet2 is an updated list that is retrieved, with updated lines and new lines. Within the lists in column A is a unique ID for every entry in numeric value. What is trying to attempt in the VBA below is to go through every unique ID in sheet2, look for a match in sheet1, replace that entire row values with the new values from sheet2 if there is a match, if there is no match it needs to be placed in the last blank row (+1from xlUp). I have tried other ways that are not below like using scripting.dictionary, but I am not successful so far.
VBA Code:
Sub test()
Dim enter As Worksheet
Dim take As Worksheet
Set enter = Worksheets("Sheet1")
Set take = Worksheets("Sheet2")
Dim a1 As Long
Dim b1 As Long
Dim c1 As Long
a1 = take.Cells(Rows.Count, 1).End(xlUp).Row
b1 = enter.Cells(Rows.Count, 1).End(xlUp).Row
c1 = enter.Cells(Rows.Count, 1).End(xlUp).Row + 1
For i = 1 To a1 'this statement works fine to find the matching value to replace.
For K = 1 To b1
If take.Cells(i, 1) = enter.Rows(K, 1) Then
enter.Rows(i).EntireRow = take.Rows(K).EntireRow.Value
End If
Next
Next
'below is other things i have tried
'For I = 1 To a1
' For J = 1 To b1
' If enter.Cells(J, 1) <> take.Cells(I, 1) Then
' enter.Rows(c1).EntireRow = take.Rows(I).EntireRow.Value
' c1 = c1 + 1
' End If
' Next
'Next
'For i = 1 To a1
' For j = 1 To b1
' If take.Cells(i, 1) = enter.Cells(j, 1) Then
' enter.Rows(j).EntireRow = take.Rows(i).EntireRow.Value
' GoTo Skip
' ElseIf j = b1 Then
' enter.Rows(c1).EntireRow = take.Rows(i).EntireRow.Value
' c1 = c1 + 1
' End If
' Next
'Skip:
'Next
End Sub
The way I am trying to do this is resulting in my every cell that the “for” is looking at to be true for the if not equal. I’m just not able to figure out how to get around this and not have every item posted multiple time below xlUp. Any help is welcomed as I am new to this forum.