Results 1 to 20 of 20

Macro not returning results

Threaded View

  1. #1
    Valued Forum Contributor
    Join Date
    01-10-2011
    Location
    swindon, england
    MS-Off Ver
    Excel 2010
    Posts
    317

    Macro not returning results

    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
    Last edited by jeskit; 02-02-2011 at 07:30 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1