So, I am a complete beginner to VBA. Yet, I have been trying to figure out the code for this using various internet sources. So my idea for this is that i have two sheets of data (say sheet1 and sheet2). Sheet1 is my master list and sheet2 has all the major data. Now, the main conditions are that if the Shell-ID of a specific row in sheet1 matches the Shell-ID in sheet2, then just update the phase of the project. But if the value does not exist, then copy other columns like name of the project, project description, phase of the project etc. for that corresponding shell-ID back into sheet1 from sheet2 into specific rows.
So far, I can only make the entire row copied onto the sheet but not specific parts that I require. Here is my code and what I have tried. Any help will be appreciated.
i have added pictures to what my worksheet looks like, for general idea. Here is my current code:
Sub CopyData() Dim sh1 As Worksheet, sh2 As Worksheet, lr As Long, i As Long, j As Long Set sh1 = Worksheets("Sheet1") Set sh2 = Worksheets("Sheet2") Application.ScreenUpdating = False With sh1 lr = .Cells(Rows.Count, 1).End(xlUp).Row + 1 End With MsgBox (lr) With sh2 j = .Cells(Rows.Count, 1).End(xlUp).Row End With MsgBox (j) For i = 2 To j If sh2.Cells(i, 1).Value = sh1.Cells(i, 1).Value Then sh2.Cells(i, 10).Value.Copy = sh1.Range("G" & lr) ElseIf sh2.Cells(i, 1).Value <> sh1.Cells(i, 1).Value Then sh2.Rows(i).Copy Destination:=sh1.Range("A" & lr) lr = lr + 1 End If Next i MsgBox ("Copying complete") End Sub