Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Copy data from range

This code should work. Change Folder, and sheet Names as required. I put
thhe total into the workbook where tthe macro is located. After the macro is
run you can manually save the file using SaveAs.

Sub GetBooks()

Folder = "C:\Temp\"
BkNames = Array("subtest1", "subtest2", "subtest3")

DestSht = ThisWorkbook.Sheets("Sheet1")
NewRow = 1

For Each Bk In BkNames
FullName = Folder & Bk & ".xls"
Set Bk = Workbooks.Open(Filename:=FullName)
With Bk.Sheets("Sheet1")
LastRow = .Range("D" & Rows.Count).End(xlUp).Row
For RowCount = 1 To LastRow
If UCase(.Range("D" & RowCount)) = "OPEN" Then
.Rows(RowCount).Copy Destination:=DestSht.Rows(NewRow)
NewRow = NewRow + 1
End If
Next RowCount
End With
Bk.Close savechanges:=False
Next Bk

End Sub

"Jumparound" wrote:

Hi guys (and girls)

This is my problem:

I got 3 workbooks (lets call them subtest1, subtest2 and subtest3)
filled with data.
All 3 workbooks have a column "D" filled with "open" or "closed"
Now i want a CommandButton that copys all rows that have column "D"
filled with "open" to a new workbook called "total"

How do i do this?

Tnx for your help!

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Copy data from range

On Nov 19, 12:36*pm, Joel wrote:
This code should work. *Change Folder, and sheet Names as required. *I put
thhe total into the workbook where tthe macro is located. *After the macro is
run you can manually save the file using SaveAs.

Sub GetBooks()

Folder = "C:\Temp\"
BkNames = Array("subtest1", "subtest2", "subtest3")

DestSht = ThisWorkbook.Sheets("Sheet1")
NewRow = 1

For Each Bk In BkNames
* *FullName = Folder & Bk & ".xls"
* *Set Bk = Workbooks.Open(Filename:=FullName)
* *With Bk.Sheets("Sheet1")
* * * LastRow = .Range("D" & Rows.Count).End(xlUp).Row
* * * For RowCount = 1 To LastRow
* * * * *If UCase(.Range("D" & RowCount)) = "OPEN" Then
* * * * * * .Rows(RowCount).Copy Destination:=DestSht.Rows(NewRow)
* * * * * * NewRow = NewRow + 1
* * * * *End If
* * * Next RowCount
* *End With
* *Bk.Close savechanges:=False
Next Bk

End Sub



"Jumparound" wrote:
Hi guys (and girls)


This is my problem:


I got 3 workbooks (lets call them subtest1, subtest2 and subtest3)
filled with data.
All 3 workbooks have a column "D" filled with "open" or "closed"
Now i want a CommandButton that copys all rows that have column "D"
filled with "open" to a new workbook called "total"


How do i do this?


Tnx for your help!- Hide quoted text -


- Show quoted text -



Thanks a lot!
It works like a charm :-D

Many many many thanks!
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to look up and copy a changing range of data ? Don New Users to Excel 2 January 29th 10 01:50 PM
macro to copy only range with data ramzi Excel Discussion (Misc queries) 2 January 29th 09 11:28 AM
cannot copy data range reference jenny Excel Discussion (Misc queries) 5 January 16th 09 09:05 AM
How do I copy data range of the same name to another tab? Amy Wong Excel Worksheet Functions 4 October 10th 06 10:48 PM
copy data range Paulw2k Excel Programming 2 April 21st 04 12:26 AM


All times are GMT +1. The time now is 02:03 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"