0

I am trying to import multiple csv-files within the same directory into my Excel sheet using VBA. The following code is working very well with just one csv-file. But I lack the knowledge to adapt my VBA script to import all data into the same Excel sheet. If anyone can help me I will be very grateful. The data from the next csv-file needs to be imported to the first empty row of the same sheet.

    Sub loadDataFromCSV()
Const csvFile = "N:\Temp voor automatisering\*.csv"
Dim ws As Worksheet, csv As Workbook, cCount As Long, cName As String

Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set ws = ThisWorkbook.Worksheets("NGSimport")
'Set ws = ThisWorkbook.ActiveSheet
Workbooks.Open csvFile
Set csv = ActiveWorkbook
cName = csv.Name
ActiveSheet.Columns("A:U").Copy
ws.Activate
ws.Range("A1:U1").PasteSpecial xlPasteValues
'cCount = Selection.Cells.Count
csv.Close

Application.DisplayAlerts = True
Application.ScreenUpdating = True

End Sub

2
  • This or this may be useful. Feb 16, 2023 at 15:19
  • Excuse for the late reply cybernetic.nomad I overlooked your comment. Thank you, I will give it a try.
    – Caroline
    Mar 1, 2023 at 12:38

0

You must log in to answer this question.

Browse other questions tagged .