I need to develop a macro that allows me to copy data from a file named 'file.csv' to a file 'data.csv'. The first file could be half empty and therefore at first I need to look for the data. The most important part is at the end when I try to paste it. It returns a strange error "Application-define or object-defined error" where there are the ***.
Sub dataComposer()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim Filename As String
Dim begin As Integer
Dim over As Integer
Dim wkbAll As Workbook
Dim wkbTemp As Workbook
Dim newSheet As Worksheet
For y1 = 1 To 1 Step 1
'Open the source file
Set wkbTemp = Workbooks.Open(Filename:=ThisWorkbook.Path & "\file.csv")
wkbTemp.Activate
'Look for the part to copy
For x1 = 1 To 200000 Step 1
If IsEmpty(Cells(x1, 1)) = False Then
begin = x1
For x2 = x1 To 300000 Step 1
If IsEmpty(Cells(x2, 1)) = True Then
over = x2
Exit For
End If
Next
Exit For
End If
Next
'Open the destination file
Set wkbTemp1 = Workbooks.Open(Filename:=ThisWorkbook.Path & "\data.csv")
'Copy the data from the source
wkbTemp.Sheets(1).Cells.Copy
Range(Cells(begin, 1), Cells(over - 1, 47)).Select
Selection.Copy
'Now, paste it into the destination
Windows("data.csv").Activate
Range(Cells(being, 1)).Select '***
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
'Save and close
wkbTemp.Close
wkbTemp1.Save
wkbTemp1.Close
Next
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub