Hi guys,
I am relatively new to VBA, and I am getting stuck with my code. What I want to achieve is to import a file on a daily basis and copy that data in another worksheet below the existing data. I keep getting the following error: "Runtime error: 1004. We can't copy because the Copy and Paste area are not the same."
I got the following code so far:
Any help would be greatly appreciated.
I am relatively new to VBA, and I am getting stuck with my code. What I want to achieve is to import a file on a daily basis and copy that data in another worksheet below the existing data. I keep getting the following error: "Runtime error: 1004. We can't copy because the Copy and Paste area are not the same."
I got the following code so far:
Code:
Sub ImportFile()
' Dimensions
Dim myPath As String
Dim folderPath As String
Dim Filename As String
Dim LastRow As Long
Dim LastColumn As Long
Dim sht As Worksheet
Dim StartCell As Range
Set sht = Worksheets("raw data")
Set StartCell = Range("A1")
' Specifications of file paths
folderPath = Application.ActiveWorkbook.Path
myPath = Application.ActiveWorkbook.FullName
Filename = Application.GetOpenFilename("Supership Import, *.csv")
'Refresh UsedRange
Worksheets("raw data").UsedRange
' Find Last Row and Column
LastRow = StartCell.SpecialCells(xlCellTypeLastCell).Row
LastColumn = StartCell.SpecialCells(xlCellTypeLastCell).Column
' Open Workbook
Workbooks.Open Filename:=Filename
Columns("G:G").Select
Selection.Insert Shift:=xlToRight
Selection.Insert Shift:=xlToRight
Columns("J:J").Select
Selection.TextToColumns Destination:=Range("G1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=True, Tab:=True, _
Semicolon:=False, Comma:=True, Space:=True, Other:=False, FieldInfo:= _
Array(Array(1, 1), Array(2, 2)), TrailingMinusNumbers:=True
Range("A:AO").Copy Destination:=StartCell(LastRow + 1, LastColumn)
Windows("Module - US.xlsm").Activate
End Sub
Last edited: