KayJay0618
New Member
- Joined
- Jul 20, 2016
- Messages
- 40
I have a workbook (BoardTime.xlsx) tracking board member time. Each board member will send me a CSV file with their information for a period of time (CSVExport.csv). I need to copy the data from columns A through E from CSVExport.csv starting in cell A2 to a worksheet in BoardTime.xlsx named Time and I need the data to be pasted in the first blank row of the Time worksheet. I've got the following code and it works like a charm EXCEPT that it doesn't paste to the first blank row - it overwrites existing starting in cell A2.
Code:
Sub TimeImport()
'
' Copy data from CSVExport file to BoardTime Reported Time Sheet first blank row
'
Dim timetrack As Workbook, timetrackname As String, timesheet As Worksheet, targetpath As String
Dim Hours As Workbook, Hoursimportname As String, Hoursimportpath As String
Application.DisplayAlerts = False
Application.ScreenUpdating = False
timetrackname = ThisWorkbook.Name
Set timetrack = Workbooks(timetrackname)
targetpath = Application.Workbooks(timetrackname).Path
Set data = timetrack.Worksheets("Time")
importname = "\CSVExport.csv"
importpath = ThisWorkbook.Path
Dim copyRange As Range
Dim lr As Long
Dim newlr As Long
Set Import = Workbooks.Open(ThisWorkbook.Path & "\CSVExport.csv")
Dim Lastrow As Integer
Lastrow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
' Paste the data in columns A through E to the last row of data
Import.Worksheets(1).Range("A2:E" & Lastrow).Copy
data.Range("A2:E" & Lastrow).PasteSpecial (xlPasteValues)
Import.Close
data.Range("A2").Select
Worksheets("Time").Activate
End Sub
Code:
Sub TimeImport()
'
' Copy data from CSVExport file to BoardTime Reported Time Sheet first blank row
'
Dim timetrack As Workbook, timetrackname As String, timesheet As Worksheet, targetpath As String
Dim Hours As Workbook, Hoursimportname As String, Hoursimportpath As String
Application.DisplayAlerts = False
Application.ScreenUpdating = False
timetrackname = ThisWorkbook.Name
Set timetrack = Workbooks(timetrackname)
targetpath = Application.Workbooks(timetrackname).Path
Set data = timetrack.Worksheets("Time")
importname = "\CSVExport.csv"
importpath = ThisWorkbook.Path
Dim copyRange As Range
Dim lr As Long
Dim newlr As Long
Set Import = Workbooks.Open(ThisWorkbook.Path & "\CSVExport.csv")
Dim Lastrow As Integer
Lastrow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
' Paste the data in columns A through E to the last row of data
Import.Worksheets(1).Range("A2:E" & Lastrow).Copy
data.Range("A2:E" & Lastrow).PasteSpecial (xlPasteValues)
Import.Close
data.Range("A2").Select
Worksheets("Time").Activate
End Sub