Copy data from different csv files into one sheet

Kalfel

New Member
Joined
Feb 27, 2017
Messages
4
Found the below code to be working, but have two constrains. Each rows from the source file is copied in the last empty column. The string is gets pasted with double quotes.
Sub ImportCSV()
<code style="margin: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; white-space: inherit;">Dim strSourcePath As String
Dim strDestPath As String
Dim strFile As String
Dim strData As String
Dim x As Variant
Dim Cnt As Long
Dim r As Long
Dim c As Long

Application
.ScreenUpdating = False

'Change the path to the source folder accordingly
strSourcePath
= "C:\Users\xxxx\Documents\test"

If Right(strSourcePath, 1) <> "" Then strSourcePath = strSourcePath & ""

'Change the path to the destination folder accordingly
strDestPath
= "C:\Users\xxxx\Documents\test1"

If Right(strDestPath, 1) <> "" Then strDestPath = strDestPath & ""

strFile
= Dir(strSourcePath & "*.csv")

Do While Len(strFile) > 0
Cnt
= Cnt + 1
r
= Cells(Rows.Count, "A").End(xlUp).Row + 1
Open strSourcePath
& strFile For Input As #1
Do Until EOF(1)
Line Input
#1, strData
x
= Split(strData, ",")
For c = 0 To UBound(x)
Cells
(r, c + 1).Value = Trim(x(c))
Next c
r
= r + 1
Loop
Close
#1
Name strSourcePath
& strFile As strDestPath & strFile
strFile
= Dir
Loop

Application
.ScreenUpdating = True

If Cnt = 0 Then _
MsgBox
"No CSV files were found...", vbExclamation</code>End Sub Kindly help me to fix this.
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

Forum statistics

Threads
1,223,243
Messages
6,170,971
Members
452,371
Latest member
Frana

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
Back
Top