Good morning,
I am having a problem with my macro. It seems to import all the csv files in, but they paste in sporadic places instead of just column A. I like the way the msoFileDialogFilePicker and InitialView are working, just cant get the array right.
Any advice?? Thank you!
Sub ImportCSV()
Dim Str1 As String
Dim i As Integer
Dim fd As FileDialog
Dim FileChosen As Integer
Dim FileName As String
Dim j As Long
Dim Boo1 As Boolean
'With Application.FileDialog(msoFileDialogFilePicker)
Set fd = Application.FileDialog(msoFileDialogFilePicker)
fd.InitialFileName = "N:\Folder\Files\2015\"
fd.InitialView = msoFileDialogViewList
With fd
.AllowMultiSelect = True
.Filters.Clear
.Filters.Add "Comma delemited file (*.csv)", "*.csv"
.Filters.Add "Text files (*.txt)", "*.txt"
.Filters.Add "All Files (*.*)", "*.*"
FileChosen = fd.Show
'fd.Show
If .SelectedItems.Count > 0 Then
Worksheets(1).Activate
j = 1
For i = 1 To .SelectedItems.Count
Str1 = "TEXT;" & .SelectedItems.Item(i)
With ActiveSheet.QueryTables.Add(Connection:=Str1, Destination:=Cells(j, 1))
.TextFileSemicolonDelimiter = True
.Refresh BackgroundQuery:=False
End With
Boo1 = False
While Boo1 = False
j = j + 1
If Cells(j, i).Value = "" Then
Boo1 = True
End If
Wend
Next
End If
End With
End Sub
Bookmarks