I am completely new to VBA and I am trying to develop a macro in a workbook (Backup.xls). The main functionality of the macro is:
1. It would open another workbook (Source.xls).
2. This workbook is regularly updated. The previously updated rows are replaced with new rows everyday.
3. Copy the newly updated row.
4. Paste the copied row after the previously inserted row.
The number of rows that can be present in the source.xls can vary from 0 to n.
Let us assume that in my Backup.xls, the number of rows that are present currently is say 16.
Thus my requirement is:
The macro would open source.xls, copy the 3 newly inserted rows (say) and then paste the same from 17th row. The first row is the column name which is same in both the excels.
I have made up the following piece of code:
Sub FetchData()The problem that I am facing is after I am executing the above piece of code, the backup.xls is having the newly inserted rows only. The previously inserted rows are overwritten.
Dim SourceFile As String
Dim HomeBook As String
Dim OtherBook As String
Sheets("BackUp").Select
SourceFile = Range("A1").Value
HomeBook = ActiveWorkbook.Name
Workbooks.Open Filename:="Source.xls"
OtherBook = ActiveWorkbook.Name
Cells.Select
Selection.Copy
Windows(HomeBook).Activate
Sheets("BackUp").Select
Range("A1").Select
ActiveSheet.Paste
Application.DisplayAlerts = False
Workbooks(OtherBook).Close SaveChanges:=False
Application.DisplayAlerts = True
End Sub