Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88075

Search and update column data based on unique row value and if new value then update as last row VBA

$
0
0

I am creating a VBA macro which will compare unique values (in column A) from Master and child sheet. Both Master and Child sheets have same columns ID (column A), Closed_count (column B), Pending_count (column C). If we find match in column "A" then will update corresponding columns "B" and "C" in master sheet.

I have written the code shown below which can search and update the matching columns but if there is new entry then I wold like that to be updated after last row in "Master" sheet. I am stuck here. Could you please help?

Sub Search_and_update_Data()

Dim Master, Child As Worksheet
Dim i, j, mlr, clr As Long
Set Master = Worksheets("Master")
Set Child = Worksheets("Child")

mlr = Master.Cells(Rows.Count, 1).End(xlUp).Row 'gets last row from Master sheet
clr = Child.Cells(Rows.Count, 1).End(xlUp).Row 'gets last row from Child sheet

For i = 2 To mlr
    For j = 2 To clr    
    'Checks column "A" with unique value from both sheets and update records in "A","B" and "C" column in Master sheet

        If Master.Cells(i, 1).Value = Child.Cells(j, 1) Then
        Master.Cells(i, 1).Value = Child.Cells(j, 1)
        Master.Cells(i, 2).Value = Child.Cells(j, 2)
        Master.Cells(i, 3).Value = Child.Cells(j, 3)
        End If
    Next j
Next i
End Sub

Viewing all articles
Browse latest Browse all 88075

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>