can you review this macro plz?

cmefly

Well-known Member
Joined
May 13, 2003
Messages
683
hi,

I've got the following macro that goes into every excel file in a certain directory and copies certain cells to another worksheet...for some reason, it's not finding any files even though i clearly have 65 files in the directory...any help would be greatly appreciated.

Sub fetch2011columns()
Dim a, k As Integer
Dim strPath As String
Dim strFileName As String
Dim i As Integer
Dim vaFileName As Variant


strPath = "C:\2011"
a = 1

With Application.FileSearch
.LookIn = strPath
.Filename = ".xls"


For Each vaFileName In .FoundFiles
Workbooks.Open vaFileName

With ActiveWorkbook
.Worksheets("DataFetcher").Select
.Range("C5:C240, e5:e240,j5:j240,m5:m240").Select
.Close
End With

Windows("2011extractor").Activate
Range("A" & a).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False

a = 240 * k + 1

Next

End With

End Sub


thanks,

Marc
 
Mistake
I made a typo in changing back the file path.

Edit this:

strPath = "C:\2001"
 
Upvote 0

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
bertie,

is it working for you?

i can't seem to get past the paste special section! ahhhh
 
Upvote 0
no worries - i caught that error....
i'm trying so many different things but can't get the paste or paste special to work...
 
Upvote 0
Yes, it's working for me.

If you can't get past the PasteSpecial line then check the name of the worksheet you are pasting into is correct. 2011extractor

When testing I just copied that into the sheetname.

If you send me a pm with your eMail I can forward the file I was working on.

Bertie
 
Upvote 0
yeah! it worked...i've got to learn how to copy and paste properly!

thank you for your time and patience bertie - you have no idea how much time you just saved me!
 
Upvote 0

Forum statistics

Threads
1,224,592
Messages
6,179,789
Members
452,942
Latest member
VijayNewtoExcel

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