Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / December 2007

Tip: Looking for answers? Try searching our database.

How do i copy a cell from a workbook to another workbook?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Tony - 20 Dec 2007 02:52 GMT
Hi

I have a data in Cells G25. And I have 20 xls files in a folder.

What i want to do is I would like to copy the cells G25 from this 20 xls
files into a new workbook. How could I do that?

Please can i have some help?

Thanks a lot

Tony
Mark Ivey - 20 Dec 2007 03:11 GMT
Here is one method...

You will need a workbook with the filename "Work.xls"  for this one to work
out right. Also you can only have the "Work.xls" file open when you run this
macro or it will not work correctly.

With the workbook "Work.xls" open, make a new module and paste the following
code...

Then run the macro.

Sub OpenFiles()
   Dim fn As Variant, f As Integer, i As Integer, counter As Integer

   i = 1
   fn = Application.GetOpenFilename("CSV Files,*.csv", _
                                    1, "Select One Or More Files To Open",
, True)
   If TypeName(fn) = "Boolean" Then Exit Sub
   For f = 1 To UBound(fn)
       Debug.Print "Selected file #" & f & ": " & fn(f)
       Workbooks.Open fn(f)

       While i = 1

           Range("G25").Select
           Selection.Copy
           Windows("Work.xls").Activate
           Range("A1").Select
           ActiveSheet.Paste

           i = i + 1
       Wend

       If (f > 1) Then

           While (i <= f)
               Range("G25").Select
               Selection.Copy
               Windows("Work.xls").Activate
               Range("A1").Select
               Cells(i, 1).Select
               ActiveSheet.Paste

               i = i + 1
           Wend

       End If

       ActiveWindow.ActivateNext
       ActiveWindow.Close False

   Next f
End Sub

> Hi
>
[quoted text clipped - 8 lines]
>
> Tony
Mark Ivey - 20 Dec 2007 03:18 GMT
You needed it for XLS files... my bad...  try the following macro:

Sub OpenFiles()
   Dim fn As Variant, f As Integer, i As Integer, counter As Integer

   i = 1
   fn = Application.GetOpenFilename("Excel Files,*.xls", _
                                    1, "Select One Or More Files To Open",
, True)
   If TypeName(fn) = "Boolean" Then Exit Sub
   For f = 1 To UBound(fn)
       Debug.Print "Selected file #" & f & ": " & fn(f)
       Workbooks.Open fn(f)

       While i = 1

           Range("G25").Select
           Selection.Copy
           Windows("Work.xls").Activate
           Range("A1").Select
           ActiveSheet.Paste

           i = i + 1
       Wend

       If (f > 1) Then

           While (i <= f)
               Range("G25").Select
               Selection.Copy
               Windows("Work.xls").Activate
               Range("A1").Select
               Cells(i, 1).Select
               ActiveSheet.Paste

               i = i + 1
           Wend

       End If

       ActiveWindow.ActivateNext
       ActiveWindow.Close False

   Next f
End Sub

> Here is one method...
>
[quoted text clipped - 63 lines]
>>
>> Tony
Tony - 20 Dec 2007 03:40 GMT
I got a Excel VBA program which is used to generate report.

All i want to do is

1. Click the generate button
2. Copy the Cells G25 from 10 folders with 20 different xls files
3. generate it to my existing workbook performance score worksheet

Is your macro able to do that?

Thanks for your help

Tony
Mark Ivey - 20 Dec 2007 03:49 GMT
Not as it is...

It would need some work...

If you need more in-depth help, give me the path these files are located in
and I will see what I can do from there.

Mark

> I got a Excel VBA program which is used to generate report.
>
[quoted text clipped - 9 lines]
>
> Tony
Tony - 20 Dec 2007 04:01 GMT
maybe i could send it to you by e-mail? is it ok?

> Not as it is...
>
[quoted text clipped - 18 lines]
> >
> > Tony
Mark Ivey - 20 Dec 2007 04:00 GMT
No problem...

> maybe i could send it to you by e-mail? is it ok?
>
[quoted text clipped - 21 lines]
>> >
>> > Tony
Tony - 20 Dec 2007 04:21 GMT
sent... please check your e-mail

thanks

> No problem...
>
[quoted text clipped - 23 lines]
> >> >
> >> > Tony
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.