Import CVS File into existing table

Elifly

New Member
Joined
Oct 12, 2020
Messages
13
Office Version
  1. 365
Platform
  1. Windows
Hey everyone :)

I'm looking for a VBA for importing CVS Files to an existing workbook.

- It lets me pick multiple CSV file via an Open File dialogue
- The CVS File should be copied to the last written column (end of the existing table)
- The CVS File could be opened and closed again

I'm sure this has been written hundreds of times, but I can't seem to find a solution that fits my needs best

I have a code that works pretty well besides it copies my file to the top of my workbook

VBA Code:
Sub CSV_Import()
Dim dateien, i, lastrow
lastrow = 1
dateien = Application.GetOpenFilename _
("csv-Dateien (*.csv), *.csv", MultiSelect:=True)
If IsArray(dateien) Then
For i = 1 To UBound(dateien)
Workbooks.Open dateien(i), local:=True
With ThisWorkbook.Sheets(1)
ActiveSheet.UsedRange.Copy Destination:=.Range("A" & lastrow)
lastrow = .UsedRange.Rows.Count + 1
End With
ActiveWorkbook.Close False
Next i
End If
End Sub


Looking forward to your solutions :)

Thank you!
 

Some videos you may like

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,253
Office Version
  1. 365
Platform
  1. Windows
Hi & welcome to MrExcel.
How about
VBA Code:
Sub CSV_Import()
   Dim dateien As Variant
   Dim i As Long
   
   dateien = Application.GetOpenFilename _
      ("csv-Dateien (*.csv), *.csv", MultiSelect:=True)
   If IsArray(dateien) Then
      For i = 1 To UBound(dateien)
         Workbooks.Open dateien(i), local:=True
         With ThisWorkbook.Sheets(1)
            ActiveSheet.UsedRange.Copy Destination:=.Cells(1, .Columns.Count).End(xlToLeft).Offset(, 1)
         End With
         ActiveWorkbook.Close False
      Next i
   End If
End Sub
 

Elifly

New Member
Joined
Oct 12, 2020
Messages
13
Office Version
  1. 365
Platform
  1. Windows
It worked !
Thank you very much :)
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,253
Office Version
  1. 365
Platform
  1. Windows
You're welcome & thanks for the feedback.
 

Watch MrExcel Video

Forum statistics

Threads
1,127,001
Messages
5,622,125
Members
415,878
Latest member
jjj12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top