Hi
I created the code below which should loop through a folder find all the CSV files and copy the values in cell range E2:E10000 and paste the values in the second column in the workbook in the template workbook and continue going along the columns.
The code runs without error but it does not return any results and i know there are CSV files in the location i am looping through.
Sub Macro2()
'Define Variables
Dim StrFile As String
Dim StrFldr As String
Dim ExtractCSV As Workbook
Dim ExtractCSVSheet As Worksheet
Dim lnextCol As Long
Dim Template As Workbook
Dim TemplateExtract As Worksheet
'Set StrFldr & StrFile Variables
StrFldr = "C:\Documents and Settings\SeymourJ\Desktop\Tasks\HondaExtractMacro\"
StrFile = Dir(StrFldr & "\.csv")
Application.CutCopyMode = xlCopy
Set Template = Application.Workbooks.Open("C:\Documents and Settings\SeymourJ\Desktop\Tasks\HondaExtractMacro\DealerData_Extract_Feed_Template.xls")
Set TemplateExtract = Template.Sheets("ExtractData")
lnextCol = 2
If Len(StrFile) > 0 Then
Do
Set ExtractCSV = WorksBooks.Open(Filename:=StrFldr & StrFile)
Set ExtractCSVSheet = ExtractCSV.Sheets(1)
Set i = Range("E2:E10000").SpecialCells(xlCellTypeConstants, xlTextValues).Copy
With TemplateExtract
.Columns(lnextCol, 2) = i.PasteSpecial
End With
lnextCol = lnextCol + 1
ExtractCSV.Close
StrFile = Dir
Application.StatusBar = StrFile
Loop Until Len(StrFile) = 0
End If
Set Template = Nothing
Set ExtractCSV = Nothing
Set TemplateExtract = Nothing
Set ExtractCSVSheet = Nothing
End Sub
Does anyone know what i have done wrong in the code?
Thanks
Jeskit
Bookmarks