Results 1 to 11 of 11

Cycling through files in a folder

Threaded View

KateMolloy Cycling through files in a... 09-21-2009, 07:28 AM
sweep Re: Cycling through files in... 09-21-2009, 07:38 AM
KateMolloy Re: Cycling through files in... 09-21-2009, 08:33 AM
sweep Re: Cycling through files in... 09-21-2009, 09:08 AM
KateMolloy Re: Cycling through files in... 09-25-2009, 06:07 AM
sweep Re: Cycling through files in... 09-25-2009, 06:34 AM
KateMolloy Re: Cycling through files in... 09-25-2009, 11:38 AM
jaslake Re: Cycling through files in... 09-25-2009, 09:24 PM
broro183 Re: Cycling through files in... 09-26-2009, 06:47 PM
KateMolloy Re: Cycling through files in... 09-28-2009, 08:49 AM
broro183 Re: Cycling through files in... 09-28-2009, 04:18 PM
  1. #1
    Registered User
    Join Date
    09-21-2009
    Location
    Nottingham, UK
    MS-Off Ver
    Excel 2003
    Posts
    5

    Cycling through files in a folder

    Hi all,

    I'm a novice with VB, so go easy on me. I'm trying to write a macro to copy the same couple of cells from hundreds of excel files and paste them into one summary file. What I've written so far is:

    Sub Test()
    Dim x As Integer
    Dim y As Integer
    Dim name As String
    Dim name2 As String
    Dim wb As String
    Dim wb2 As String
    x = 3
    y = 10
    name = "WM19-1-014_00"
    name2 = "WM19-1-014_0"
    Do While (x < 10)
    wb = "name" & "x" & ".xls"
    Workbooks("wb").Activate
    Range("A3:B3").Copy
    Workbooks("data").Worksheets("Sheet1").Activate
    Cells(A, "2*x").Paste
    x = x + 1
    Loop
    Do While (y < 63)
    wb2 = "name2" & "y" & ".xls"
    Workbooks("wb2").Activate
    Range("A3:B3").Copy
    Workbooks("data").Worksheets("Sheet1").Activate
    Cells(A, "2*y").Paste
    y = y + 1
    Loop
    End Sub
    Forgive the clumsy break down of the files; they range from 001 to 063, and since I don't know how to set x as a three digit number I decided to have a section for 1-9 and a second section (with the same code) for 10-63.

    The problem I think I'm having is in referencing the workbook (the debugger always stops on the worksheets(wb).Activate line). Ideally I'd like the macro to open the files itself, but given that I can't even make it work when they're open I think I should start small. The issue, I believe, is that I'm not referencing the file correctly, since I'm trying to use the 'name + x' format to cycle through the files, and either I'm doing it wrong or this sort of variable referencing isn't suitable for the function. I've tried all manner of different tactics to get the activate workbook function liking my workbook name, but have had no luck.

    Any help would be hugely appreciated, and once again, forgive my unsubtle coding.

    Kate
    Last edited by KateMolloy; 09-28-2009 at 08:55 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