Solved

Moving data across files

Posted on 2000-03-02
4
140 Views
Last Modified: 2010-05-02
I have a whole bunch of Excle spreadsheets in a directory. They are all of the same format. I don't use any standard naming conventions. I need to copy some of this data onto a new spreadsheet.

Is there some way that I can say:

for every file in directory 12345
open the file
select data in j1:j100
paste the data into column a(or b, c, etc) of my new file
open the next source file
0
Comment
Question by:panikos
  • 2
4 Comments
 
LVL 22

Accepted Solution

by:
ture earned 100 total points
ID: 2576456
Panikos,

This Excel VBA procedure should do exactly what you ask for.

Sub HelpPanikos()
  Dim rngDest As Range
  Dim strPath As String
  Dim strFileName As String
 
  Set rngDest = ThisWorkbook.Sheets("Sheet1").Range("A1")
  strPath = "c:\12345\"
  strFileName = Dir(strPath & "*.xls")
 
  Do Until strFileName = ""
    With Workbooks.Open(strPath & strFileName)
      .Sheets("Sheet1").Range("J1:J100").Copy rngDest
      .Close SaveChanges:=False
    End With
    strFileName = Dir()
    Set rngDest = rngDest.Offset(0, 1)
  Loop
End Sub

Ture Magnusson
Karlstad, Sweden
0
 

Author Comment

by:panikos
ID: 2576524
Thank you very much Ture. How do I go about giving the points to you? Is there some way that I can accept this as an answer rather than as a comment?
0
 
LVL 2

Expert Comment

by:p_biggelaar
ID: 2576581
There should be a button on the green 'Comment' line right above his comment (or something like that)

Please make sure you accept his comment as an answer, not mine! ;-)
0
 
LVL 22

Expert Comment

by:ture
ID: 2576615
panikos,
Thank you for the points. I'm glad that I could help you.

p_biggelaar,
Thanks for your friendly directions to panikos.

/Ture
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question