I'm using two files let's name it File 1 and File 2 my script append the data from File 1 to File 2 now every time I append File 2 i want insert Current Date from my Column.
File 1:
Header 1 | Header 2 | Header 3| 1 | 1 | | 1 | 1 | | File 2
Header 1 | Header 2 | Header 3| a | a | 3/3/2016| a | a | 3/3/2016| Sample Output:
Header 1 | Header 2 | Header 3| a | a |3/3/2016 | a | a |3/3/2016 | 1 | 1 |4/4/2016 | 1 | 1 |4/4/2016 | As you can see the sample output above inserted the current date in `Header 3.
My problem is that if i append the data from File 2 it densest return the current date in Header 3 but if I append it again it updates the last one. to make it clear let's give another example.
Sample Out: (This is the output of my script)
Header 1 | Header 2 | Header 3| a | a |3/3/2016 | a | a |3/3/2016 | 1 | 1 | | 1 | 1 | | If I append again the data from File 1 this is now the output
Header 1 | Header 2 | Header 3| a | a |3/3/2016 | a | a |3/3/2016 | 1 | 1 |4/4/2016 | 1 | 1 |4/4/2016 | 1 | 1 | | 1 | 1 | | I want to insert the current date every time i append a new data, my code insert the date one step behind and i'm connfused gagin with my code @.@ Please Help me!
My Code:
Public Sub addweeklydata() Dim file1 As Excel.Workbook Dim file2 As Excel.Workbook Dim Sheet1 As Worksheet Dim Sheet2 As Worksheet Dim Rng As Range Set Sheet1 = Workbooks.Open(TextBox1.Text).Sheets(1) Set Sheet2 = Workbooks.Open(TextBox2.Text).Sheets(1) lastRow = Sheet2.Range("A" & Rows.Count).End(xlUp).Row For i = 2 To lastRow Sheet2.Cells(i, 4).Value = Date Set Rng = Sheet1.Range("A1").CurrentRegion 'assuming no blank rows/column Set Rng = Rng.Offset(1, 0).Resize(Rng.Rows.Count - 1, Rng.Columns.Count) 'exclude header Next Sheet2.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Resize( _ Rng.Rows.Count, Rng.Columns.Count).Value = Rng.Value Sheet2.Parent.Close True 'save changes Sheet1.Parent.Close False 'don't save End Sub