Need to copy from sourcesheet to destination sheet only the new data entered based on serial no on the source sheet

Chitaah

New Member
Joined
May 18, 2021
Messages
1
Office Version
  1. 2016
Platform
  1. Windows
I am totally new to Excel VBA. But I have a requirement to copy some data from let us say sheet1 to sheet2. I have several columns and rows in sheet1 (source sheet). Now I have to copy only Five columns data from within that where "Ferro Manganese" found in particular one coloum and if found then just copy the data's from the rows of the other 4 columns also and then paste in to the destination rows of the specified column there in Sheet2. Till this step I have done it successfully. Now the users are entering new data to the source sheet the next day and I only need to update those data to the destination sheet. The new data can be selected based on new Serial no on the sheet1 which is available in coloum "A". For every new entry they enter a increased serial number (Which is unique). so If I can check the "Ferro Manganese" condition from the newly entered serial number (from the point Serial no increased) then I can only copy those new data to the destination sheet using the successful code i am attaching it here. I need to learn how to write that extra if condition for increased serial no condition depending on which the paste function will work for only the new data. Due to office data populated in the sheet I could not upload it. But from the code the description I think you masters will understand it easily.
Please help me.

VBA Code:
Sub Datafetch()

Dim lastrow As Long, erow As Long

Dim LastRowIndex As Integer
Dim RowIndex As Integer
Dim UsedRng As Range


lastrow = Worksheets("SIPL Details").Cells(Rows.Count, 1).End(xlUp).Row
erow = Worksheets("Ferro Tracking").Cells(Rows.Count, 1).End(xlUp).Row


For i = 2 To lastrow

If Worksheets("SIPL Details").Cells(i, 7).Value = "Ferro Manganese" Or Worksheets("SIPL Details").Cells(i, 7).Value = "Silico Manganese" Then

Worksheets("SIPL Details").Cells(i, 3).Copy
Worksheets("SIPL Details").Paste Destination:=Worksheets("Ferro Tracking").Cells(erow + i, 2)
Worksheets("Ferro Tracking").Cells(erow + i, 1).Value = "SIPL"
Worksheets("SIPL Details").Cells(i, 7).Copy
Worksheets("SIPL Details").Paste Destination:=Worksheets("Ferro Tracking").Cells(erow + i, 4)
Worksheets("Ferro Tracking").Cells(erow + i, 1).Value = "SIPL"
Worksheets("SIPL Details").Cells(i, 14).Copy
Worksheets("SIPL Details").Paste Destination:=Worksheets("Ferro Tracking").Cells(erow + i, 7)
Worksheets("Ferro Tracking").Cells(erow + i, 1).Value = "SIPL"
Worksheets("SIPL Details").Cells(i, 9).Copy
Worksheets("SIPL Details").Paste Destination:=Worksheets("Ferro Tracking").Cells(erow + i, 11)
Worksheets("Ferro Tracking").Cells(erow + i, 1).Value = "SIPL"
Worksheets("SIPL Details").Cells(i, 5).Copy
Worksheets("SIPL Details").Paste Destination:=Worksheets("Ferro Tracking").Cells(erow + i, 13)
Worksheets("Ferro Tracking").Cells(erow + i, 1).Value = "SIPL"



End If


Next i


For i = 2 To lastrow

If Worksheets("ESPL Details").Cells(i, 7).Value = "Ferro Manganese" Or Worksheets("ESPL Details").Cells(i, 7).Value = "Silico Manganese" Then

Worksheets("ESPL Details").Cells(i, 3).Copy
Worksheets("ESPL Details").Paste Destination:=Worksheets("Ferro Tracking").Cells(erow + i, 2)
Worksheets("Ferro Tracking").Cells(erow + i, 1).Value = "ESPL"
Worksheets("ESPL Details").Cells(i, 7).Copy
Worksheets("ESPL Details").Paste Destination:=Worksheets("Ferro Tracking").Cells(erow + i, 4)
Worksheets("Ferro Tracking").Cells(erow + i, 1).Value = "ESPL"
Worksheets("ESPL Details").Cells(i, 14).Copy
Worksheets("ESPL Details").Paste Destination:=Worksheets("Ferro Tracking").Cells(erow + i, 7)
Worksheets("Ferro Tracking").Cells(erow + i, 1).Value = "ESPL"
Worksheets("ESPL Details").Cells(i, 9).Copy
Worksheets("ESPL Details").Paste Destination:=Worksheets("Ferro Tracking").Cells(erow + i, 11)
Worksheets("Ferro Tracking").Cells(erow + i, 1).Value = "ESPL"
Worksheets("ESPL Details").Cells(i, 5).Copy
Worksheets("ESPL Details").Paste Destination:=Worksheets("Ferro Tracking").Cells(erow + i, 13)
Worksheets("Ferro Tracking").Cells(erow + i, 1).Value = "ESPL"



End If


Next i


For i = 2 To lastrow

If Worksheets("BSIPL Details").Cells(i, 7).Value = "Ferro Manganese" Or Worksheets("BSIPL Details").Cells(i, 7).Value = "Silico Manganese" Then

Worksheets("BSIPL Details").Cells(i, 3).Copy
Worksheets("BSIPL Details").Paste Destination:=Worksheets("Ferro Tracking").Cells(erow + i, 2)
Worksheets("Ferro Tracking").Cells(erow + i, 1).Value = "BSIPL"
Worksheets("BSIPL Details").Cells(i, 7).Copy
Worksheets("BSIPL Details").Paste Destination:=Worksheets("Ferro Tracking").Cells(erow + i, 4)
Worksheets("Ferro Tracking").Cells(erow + i, 1).Value = "BSIPL"
Worksheets("BSIPL Details").Cells(i, 14).Copy
Worksheets("BSIPL Details").Paste Destination:=Worksheets("Ferro Tracking").Cells(erow + i, 7)
Worksheets("Ferro Tracking").Cells(erow + i, 1).Value = "BSIPL"
Worksheets("BSIPL Details").Cells(i, 9).Copy
Worksheets("BSIPL Details").Paste Destination:=Worksheets("Ferro Tracking").Cells(erow + i, 11)
Worksheets("Ferro Tracking").Cells(erow + i, 1).Value = "BSIPL"
Worksheets("BSIPL Details").Cells(i, 5).Copy
Worksheets("BSIPL Details").Paste Destination:=Worksheets("Ferro Tracking").Cells(erow + i, 13)
Worksheets("Ferro Tracking").Cells(erow + i, 1).Value = "BSIPL"



End If


Next i




    Set UsedRng = ActiveSheet.UsedRange
    LastRowIndex = UsedRng.Row - 1 + UsedRng.Rows.Count
    Application.ScreenUpdating = False
 
    For RowIndex = LastRowIndex To 1 Step -1
        If Application.CountA(Rows(RowIndex)) = 0 Then
            Rows(RowIndex).Delete
        End If
    Next RowIndex
 
    Application.ScreenUpdating = True

End Sub
 
Last edited by a moderator:

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).

Forum statistics

Threads
1,214,911
Messages
6,122,198
Members
449,072
Latest member
DW Draft

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top