PC Review


Reply
Thread Tools Rate Thread

Copy data from range

 
 
Jumparound
Guest
Posts: n/a
 
      19th Nov 2008
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!
 
Reply With Quote
 
 
 
 
Joel
Guest
Posts: n/a
 
      19th Nov 2008
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!
>

 
Reply With Quote
 
Jumparound
Guest
Posts: n/a
 
      19th Nov 2008
On Nov 19, 12:36*pm, Joel <J...@discussions.microsoft.com> 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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Use data fed in adjacent cells to sort and copy the data to spec named range sri_gs Microsoft Excel Discussion 0 12th Apr 2010 02:07 PM
Copy Range Data Macro Cheri Microsoft Excel Misc 9 12th Apr 2008 03:46 AM
How do I copy data range of the same name to another tab? =?Utf-8?B?QW15IFdvbmc=?= Microsoft Excel Worksheet Functions 4 10th Oct 2006 10:48 PM
copy data range gav meredith Microsoft Excel Programming 3 21st Apr 2004 12:26 AM
Copy a range of data then E-Mail Bob Microsoft Excel Programming 0 7th Jan 2004 03:55 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:07 AM.