Hi,
I'm looking for some advice with a new macro I have made.
I've previously created a number of macros which open files, copy data and then process/paste it into another sheet. This time I'm somehow not able to paste the data into the correct sheet however.
I've trimmed the code down below to show the core issue in a simplified form.
The data is copied from a csv file with only one sheet in it, and then should be pasted into the "Data" sheet in my main workbook. The problem is despite closing the csv file and activating the Data sheet, the data is still pasted into a different sheet in the main workbook.
Any help on this would be much appreciated.
Thanks in advance,
Wingers
I'm looking for some advice with a new macro I have made.
I've previously created a number of macros which open files, copy data and then process/paste it into another sheet. This time I'm somehow not able to paste the data into the correct sheet however.
I've trimmed the code down below to show the core issue in a simplified form.
The data is copied from a csv file with only one sheet in it, and then should be pasted into the "Data" sheet in my main workbook. The problem is despite closing the csv file and activating the Data sheet, the data is still pasted into a different sheet in the main workbook.
Any help on this would be much appreciated.
Thanks in advance,
Wingers
VBA Code:
Dim StrFile As String
Dim Folder As String
Dim SessionName As String
Dim Current As Workbook
Dim csv_file As Workbook
'Set Starting values
Application.ScreenUpdating = False
Set Current = ActiveWorkbook
Folder = Range("Folder").Value
StrFile = Dir(Folder)
Do While Len(StrFile) > 0
Workbooks.Open Filename:=Folder & StrFile
Set csv_file = ActiveWorkbook
'Collect data
SessionName = Left(StrFile, Len(StrFile) - 4)
csv_file.Close
Current.Activate
Sheets("Data").Activate
'Paste data
Cells(5, 1).Value = SessionName
StrFile = Dir
Loop
Application.ScreenUpdating = True