PC Review


Reply
Thread Tools Rate Thread

Copy and paste to corporate sheet

 
 
=?Utf-8?B?TWFyaWU=?=
Guest
Posts: n/a
 
      13th Jan 2007
I am working with 6 files. I need to copy the data from a sheet (within each
workbook/file) named 'substandard' and paste the information into the
'substandard' sheet in the master file. To do this I have been opening the
master file, placing the cursor where I want the information, opening the
file I wish to copy from, selecting the substandard sheet, copying the
information from the sheet and choosing paste special to the master file.
This takes forever. The files are all located in K:\fab\fab.xls,
K:\csb\csb.xls, K:\bsf\bsf.xls, K:\bag\bag.xls K:\bnp\bnp.xls to be
pasted into K:\corp\corp.xls. The sheets to select from within the files is
named 'substandard' - all with the same headings. I need to copy starting
from cell A6.
The sheets all have different amounts of data so I can't set a static range
to copy. And I don't know where it will need to be pasted in the master
sheet, or in other words the next empty row.

I know how to record a macro with the macro writer, but that is about it and
since the amount of data varies I am stumped.

Any suggestions??
Thanks for any help.
Marie
 
Reply With Quote
 
 
 
 
Ron de Bruin
Guest
Posts: n/a
 
      13th Jan 2007
You can start here Marie
http://www.rondebruin.nl/copy3.htm

--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Marie" <(E-Mail Removed)> wrote in message news:B900999E-1A25-4565-BF5A-(E-Mail Removed)...
>I am working with 6 files. I need to copy the data from a sheet (within each
> workbook/file) named 'substandard' and paste the information into the
> 'substandard' sheet in the master file. To do this I have been opening the
> master file, placing the cursor where I want the information, opening the
> file I wish to copy from, selecting the substandard sheet, copying the
> information from the sheet and choosing paste special to the master file.
> This takes forever. The files are all located in K:\fab\fab.xls,
> K:\csb\csb.xls, K:\bsf\bsf.xls, K:\bag\bag.xls K:\bnp\bnp.xls to be
> pasted into K:\corp\corp.xls. The sheets to select from within the files is
> named 'substandard' - all with the same headings. I need to copy starting
> from cell A6.
> The sheets all have different amounts of data so I can't set a static range
> to copy. And I don't know where it will need to be pasted in the master
> sheet, or in other words the next empty row.
>
> I know how to record a macro with the macro writer, but that is about it and
> since the amount of data varies I am stumped.
>
> Any suggestions??
> Thanks for any help.
> Marie

 
Reply With Quote
 
=?Utf-8?B?TWFyaWU=?=
Guest
Posts: n/a
 
      13th Jan 2007
Thanks! The site is very helpful!

I think the code I need is 'Copy all cells from the sheet or all cells
without the header row'

As I said I know some basic VB. I have a couple of questions about the code.

MyPath = "C:\Data"

I assume this is where I place the name of the folder I want to pull the
data from. Do all the files have to be in the same folder? In the example
above are all the files being copied in 'Data'. As I said mine are in
K:\csb\csb.xls and K:\bag\bag.xls, etc. Six different folders. Do I need to
create a folder to save them all in for this to work? They all have a sheet
that I want to copy with the same name but the files are all in different
folders.

And this line 'Copy from A2:IV? (till the last row with data on your sheet)

Is the IV like a wildcard? Does it copy everything on the sheet?

Thanks for your patience. I really appreciate it!

Marie




"Ron de Bruin" wrote:

> You can start here Marie
> http://www.rondebruin.nl/copy3.htm
>
> --
>
> Regards Ron de Bruin
> http://www.rondebruin.nl/tips.htm
>
>
> "Marie" <(E-Mail Removed)> wrote in message news:B900999E-1A25-4565-BF5A-(E-Mail Removed)...
> >I am working with 6 files. I need to copy the data from a sheet (within each
> > workbook/file) named 'substandard' and paste the information into the
> > 'substandard' sheet in the master file. To do this I have been opening the
> > master file, placing the cursor where I want the information, opening the
> > file I wish to copy from, selecting the substandard sheet, copying the
> > information from the sheet and choosing paste special to the master file.
> > This takes forever. The files are all located in K:\fab\fab.xls,
> > K:\csb\csb.xls, K:\bsf\bsf.xls, K:\bag\bag.xls K:\bnp\bnp.xls to be
> > pasted into K:\corp\corp.xls. The sheets to select from within the files is
> > named 'substandard' - all with the same headings. I need to copy starting
> > from cell A6.
> > The sheets all have different amounts of data so I can't set a static range
> > to copy. And I don't know where it will need to be pasted in the master
> > sheet, or in other words the next empty row.
> >
> > I know how to record a macro with the macro writer, but that is about it and
> > since the amount of data varies I am stumped.
> >
> > Any suggestions??
> > Thanks for any help.
> > Marie

>

 
Reply With Quote
 
Ron de Bruin
Guest
Posts: n/a
 
      13th Jan 2007
Hi Marie

> above are all the files being copied in 'Data'. As I said mine are in
> K:\csb\csb.xls and K:\bag\bag.xls, etc. Six different folders. Do I need to
> create a folder to save them all in for this to work?


Yes

I think I will create the C:\Data folder (empty folder) and run this macro first

Sub Copy_Files()
FileCopy "K:\csb\csb.xls", "C:\Data\csb.xls"
FileCopy "K:\bag\bag.xls", "C:\Data\bag.xls"
'Add four more lines
End Sub

Then try the sub from my site (copy the lastrow function also in the module)
You can change C:\Data to any folder

After the macro is ready you can use Kill to delete the files in C:\Data

If you need more help post back



--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Marie" <(E-Mail Removed)> wrote in message news:EF911C81-2C22-4EE9-98D8-(E-Mail Removed)...
> Thanks! The site is very helpful!
>
> I think the code I need is 'Copy all cells from the sheet or all cells
> without the header row'
>
> As I said I know some basic VB. I have a couple of questions about the code.
>
> MyPath = "C:\Data"
>
> I assume this is where I place the name of the folder I want to pull the
> data from. Do all the files have to be in the same folder? In the example
> above are all the files being copied in 'Data'. As I said mine are in
> K:\csb\csb.xls and K:\bag\bag.xls, etc. Six different folders. Do I need to
> create a folder to save them all in for this to work? They all have a sheet
> that I want to copy with the same name but the files are all in different
> folders.
>
> And this line 'Copy from A2:IV? (till the last row with data on your sheet)
>
> Is the IV like a wildcard? Does it copy everything on the sheet?
>
> Thanks for your patience. I really appreciate it!
>
> Marie
>
>
>
>
> "Ron de Bruin" wrote:
>
>> You can start here Marie
>> http://www.rondebruin.nl/copy3.htm
>>
>> --
>>
>> Regards Ron de Bruin
>> http://www.rondebruin.nl/tips.htm
>>
>>
>> "Marie" <(E-Mail Removed)> wrote in message news:B900999E-1A25-4565-BF5A-(E-Mail Removed)...
>> >I am working with 6 files. I need to copy the data from a sheet (within each
>> > workbook/file) named 'substandard' and paste the information into the
>> > 'substandard' sheet in the master file. To do this I have been opening the
>> > master file, placing the cursor where I want the information, opening the
>> > file I wish to copy from, selecting the substandard sheet, copying the
>> > information from the sheet and choosing paste special to the master file.
>> > This takes forever. The files are all located in K:\fab\fab.xls,
>> > K:\csb\csb.xls, K:\bsf\bsf.xls, K:\bag\bag.xls K:\bnp\bnp.xls to be
>> > pasted into K:\corp\corp.xls. The sheets to select from within the files is
>> > named 'substandard' - all with the same headings. I need to copy starting
>> > from cell A6.
>> > The sheets all have different amounts of data so I can't set a static range
>> > to copy. And I don't know where it will need to be pasted in the master
>> > sheet, or in other words the next empty row.
>> >
>> > I know how to record a macro with the macro writer, but that is about it and
>> > since the amount of data varies I am stumped.
>> >
>> > Any suggestions??
>> > Thanks for any help.
>> > Marie

>>

 
Reply With Quote
 
=?Utf-8?B?TWFyaWU=?=
Guest
Posts: n/a
 
      13th Jan 2007
I set up a couple of dummy files on my C drive to test it. In the files I
named a sheet substandard and input some data. I copied the code and
anywhere it referred to sheet1 I changed to substandard.

In the function I also changed it to A7 instead of A1 - is this right since
I want to copy from A7 - because of my headers?
What does this function do?


I am getting a Runtime error '9': subscript out of range on this line

basebook.Worksheets(Substandard).Cells.Clear

This is my code:

Sub Copy_Files()
FileCopy "C:\csb\csb.xls", "C:\Data\csb.xls"
FileCopy "C:\fab\fab.xls", "C:\Data\fab.xls"
'Add four more lines
End Sub

Function LastRow(sh As Worksheet)
On Error Resume Next
LastRow = sh.Cells.Find(What:="*", _
After:=sh.Range("A7"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
On Error GoTo 0
End Function


Sub Example7()
Dim basebook As Workbook
Dim mybook As Workbook
Dim sourceRange As Range
Dim destrange As Range
Dim rnum As Long
Dim lrow As Long
Dim SourceRcount As Long
Dim FNames As String
Dim MyPath As String
Dim SaveDriveDir As String

SaveDriveDir = CurDir
MyPath = "C:\Data"
ChDrive MyPath
ChDir MyPath

FNames = Dir("*.xls")
If Len(FNames) = 0 Then
MsgBox "No files in the Directory"
ChDrive SaveDriveDir
ChDir SaveDriveDir
Exit Sub
End If

Application.ScreenUpdating = False
Set basebook = ThisWorkbook
basebook.Worksheets(Substandard).Cells.Clear
' clear all cells on the first sheet
rnum = 1

Do While FNames <> ""
Set mybook = Workbooks.Open(FNames)
lrow = LastRow(mybook.Sheets(Substandard))
Set sourceRange = mybook.Worksheets(Substandard).Range("A2:IV" & lrow)
'Copy from A2:IV? (till the last row with data on your sheet)
SourceRcount = sourceRange.Rows.Count
Set destrange = basebook.Worksheets(Substandard).Cells(rnum, "A")

' sourceRange.Copy destrange
' Instead of this line you can use the code below to copy only the
values

With sourceRange
Set destrange =
basebook.Worksheets(Substandard).Cells(rnum, "A"). _
Resize(.Rows.Count,
..Columns.Count)
End With
destrange.Value = sourceRange.Value

mybook.Close False
rnum = rnum + SourceRcount
FNames = Dir()
Loop
ChDrive SaveDriveDir
ChDir SaveDriveDir
Application.ScreenUpdating = True
End Sub

Thanks for helping.

Marie





"Ron de Bruin" wrote:

> Hi Marie
>
> > above are all the files being copied in 'Data'. As I said mine are in
> > K:\csb\csb.xls and K:\bag\bag.xls, etc. Six different folders. Do I need to
> > create a folder to save them all in for this to work?

>
> Yes
>
> I think I will create the C:\Data folder (empty folder) and run this macro first
>
> Sub Copy_Files()
> FileCopy "K:\csb\csb.xls", "C:\Data\csb.xls"
> FileCopy "K:\bag\bag.xls", "C:\Data\bag.xls"
> 'Add four more lines
> End Sub
>
> Then try the sub from my site (copy the lastrow function also in the module)
> You can change C:\Data to any folder
>
> After the macro is ready you can use Kill to delete the files in C:\Data
>
> If you need more help post back
>
>
>
> --
>
> Regards Ron de Bruin
> http://www.rondebruin.nl/tips.htm
>
>
> "Marie" <(E-Mail Removed)> wrote in message news:EF911C81-2C22-4EE9-98D8-(E-Mail Removed)...
> > Thanks! The site is very helpful!
> >
> > I think the code I need is 'Copy all cells from the sheet or all cells
> > without the header row'
> >
> > As I said I know some basic VB. I have a couple of questions about the code.
> >
> > MyPath = "C:\Data"
> >
> > I assume this is where I place the name of the folder I want to pull the
> > data from. Do all the files have to be in the same folder? In the example
> > above are all the files being copied in 'Data'. As I said mine are in
> > K:\csb\csb.xls and K:\bag\bag.xls, etc. Six different folders. Do I need to
> > create a folder to save them all in for this to work? They all have a sheet
> > that I want to copy with the same name but the files are all in different
> > folders.
> >
> > And this line 'Copy from A2:IV? (till the last row with data on your sheet)
> >
> > Is the IV like a wildcard? Does it copy everything on the sheet?
> >
> > Thanks for your patience. I really appreciate it!
> >
> > Marie
> >
> >
> >
> >
> > "Ron de Bruin" wrote:
> >
> >> You can start here Marie
> >> http://www.rondebruin.nl/copy3.htm
> >>
> >> --
> >>
> >> Regards Ron de Bruin
> >> http://www.rondebruin.nl/tips.htm
> >>
> >>
> >> "Marie" <(E-Mail Removed)> wrote in message news:B900999E-1A25-4565-BF5A-(E-Mail Removed)...
> >> >I am working with 6 files. I need to copy the data from a sheet (within each
> >> > workbook/file) named 'substandard' and paste the information into the
> >> > 'substandard' sheet in the master file. To do this I have been opening the
> >> > master file, placing the cursor where I want the information, opening the
> >> > file I wish to copy from, selecting the substandard sheet, copying the
> >> > information from the sheet and choosing paste special to the master file.
> >> > This takes forever. The files are all located in K:\fab\fab.xls,
> >> > K:\csb\csb.xls, K:\bsf\bsf.xls, K:\bag\bag.xls K:\bnp\bnp.xls to be
> >> > pasted into K:\corp\corp.xls. The sheets to select from within the files is
> >> > named 'substandard' - all with the same headings. I need to copy starting
> >> > from cell A6.
> >> > The sheets all have different amounts of data so I can't set a static range
> >> > to copy. And I don't know where it will need to be pasted in the master
> >> > sheet, or in other words the next empty row.
> >> >
> >> > I know how to record a macro with the macro writer, but that is about it and
> >> > since the amount of data varies I am stumped.
> >> >
> >> > Any suggestions??
> >> > Thanks for any help.
> >> > Marie
> >>

>

 
Reply With Quote
 
Ron de Bruin
Guest
Posts: n/a
 
      13th Jan 2007
Hi Marie

Do not change the cell address in the function

And is the sheet where you want to copy to also named Substandard ?

Change all

(Substandard)

To

("Substandard")



--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Marie" <(E-Mail Removed)> wrote in message news:13F39DCC-0B43-497D-BAAE-(E-Mail Removed)...
>I set up a couple of dummy files on my C drive to test it. In the files I
> named a sheet substandard and input some data. I copied the code and
> anywhere it referred to sheet1 I changed to substandard.
>
> In the function I also changed it to A7 instead of A1 - is this right since
> I want to copy from A7 - because of my headers?
> What does this function do?
>
>
> I am getting a Runtime error '9': subscript out of range on this line
>
> basebook.Worksheets(Substandard).Cells.Clear
>
> This is my code:
>
> Sub Copy_Files()
> FileCopy "C:\csb\csb.xls", "C:\Data\csb.xls"
> FileCopy "C:\fab\fab.xls", "C:\Data\fab.xls"
> 'Add four more lines
> End Sub
>
> Function LastRow(sh As Worksheet)
> On Error Resume Next
> LastRow = sh.Cells.Find(What:="*", _
> After:=sh.Range("A7"), _
> Lookat:=xlPart, _
> LookIn:=xlFormulas, _
> SearchOrder:=xlByRows, _
> SearchDirection:=xlPrevious, _
> MatchCase:=False).Row
> On Error GoTo 0
> End Function
>
>
> Sub Example7()
> Dim basebook As Workbook
> Dim mybook As Workbook
> Dim sourceRange As Range
> Dim destrange As Range
> Dim rnum As Long
> Dim lrow As Long
> Dim SourceRcount As Long
> Dim FNames As String
> Dim MyPath As String
> Dim SaveDriveDir As String
>
> SaveDriveDir = CurDir
> MyPath = "C:\Data"
> ChDrive MyPath
> ChDir MyPath
>
> FNames = Dir("*.xls")
> If Len(FNames) = 0 Then
> MsgBox "No files in the Directory"
> ChDrive SaveDriveDir
> ChDir SaveDriveDir
> Exit Sub
> End If
>
> Application.ScreenUpdating = False
> Set basebook = ThisWorkbook
> basebook.Worksheets(Substandard).Cells.Clear
> ' clear all cells on the first sheet
> rnum = 1
>
> Do While FNames <> ""
> Set mybook = Workbooks.Open(FNames)
> lrow = LastRow(mybook.Sheets(Substandard))
> Set sourceRange = mybook.Worksheets(Substandard).Range("A2:IV" & lrow)
> 'Copy from A2:IV? (till the last row with data on your sheet)
> SourceRcount = sourceRange.Rows.Count
> Set destrange = basebook.Worksheets(Substandard).Cells(rnum, "A")
>
> ' sourceRange.Copy destrange
> ' Instead of this line you can use the code below to copy only the
> values
>
> With sourceRange
> Set destrange =
> basebook.Worksheets(Substandard).Cells(rnum, "A"). _
> Resize(.Rows.Count,
> .Columns.Count)
> End With
> destrange.Value = sourceRange.Value
>
> mybook.Close False
> rnum = rnum + SourceRcount
> FNames = Dir()
> Loop
> ChDrive SaveDriveDir
> ChDir SaveDriveDir
> Application.ScreenUpdating = True
> End Sub
>
> Thanks for helping.
>
> Marie
>
>
>
>
>
> "Ron de Bruin" wrote:
>
>> Hi Marie
>>
>> > above are all the files being copied in 'Data'. As I said mine are in
>> > K:\csb\csb.xls and K:\bag\bag.xls, etc. Six different folders. Do I need to
>> > create a folder to save them all in for this to work?

>>
>> Yes
>>
>> I think I will create the C:\Data folder (empty folder) and run this macro first
>>
>> Sub Copy_Files()
>> FileCopy "K:\csb\csb.xls", "C:\Data\csb.xls"
>> FileCopy "K:\bag\bag.xls", "C:\Data\bag.xls"
>> 'Add four more lines
>> End Sub
>>
>> Then try the sub from my site (copy the lastrow function also in the module)
>> You can change C:\Data to any folder
>>
>> After the macro is ready you can use Kill to delete the files in C:\Data
>>
>> If you need more help post back
>>
>>
>>
>> --
>>
>> Regards Ron de Bruin
>> http://www.rondebruin.nl/tips.htm
>>
>>
>> "Marie" <(E-Mail Removed)> wrote in message news:EF911C81-2C22-4EE9-98D8-(E-Mail Removed)...
>> > Thanks! The site is very helpful!
>> >
>> > I think the code I need is 'Copy all cells from the sheet or all cells
>> > without the header row'
>> >
>> > As I said I know some basic VB. I have a couple of questions about the code.
>> >
>> > MyPath = "C:\Data"
>> >
>> > I assume this is where I place the name of the folder I want to pull the
>> > data from. Do all the files have to be in the same folder? In the example
>> > above are all the files being copied in 'Data'. As I said mine are in
>> > K:\csb\csb.xls and K:\bag\bag.xls, etc. Six different folders. Do I need to
>> > create a folder to save them all in for this to work? They all have a sheet
>> > that I want to copy with the same name but the files are all in different
>> > folders.
>> >
>> > And this line 'Copy from A2:IV? (till the last row with data on your sheet)
>> >
>> > Is the IV like a wildcard? Does it copy everything on the sheet?
>> >
>> > Thanks for your patience. I really appreciate it!
>> >
>> > Marie
>> >
>> >
>> >
>> >
>> > "Ron de Bruin" wrote:
>> >
>> >> You can start here Marie
>> >> http://www.rondebruin.nl/copy3.htm
>> >>
>> >> --
>> >>
>> >> Regards Ron de Bruin
>> >> http://www.rondebruin.nl/tips.htm
>> >>
>> >>
>> >> "Marie" <(E-Mail Removed)> wrote in message news:B900999E-1A25-4565-BF5A-(E-Mail Removed)...
>> >> >I am working with 6 files. I need to copy the data from a sheet (within each
>> >> > workbook/file) named 'substandard' and paste the information into the
>> >> > 'substandard' sheet in the master file. To do this I have been opening the
>> >> > master file, placing the cursor where I want the information, opening the
>> >> > file I wish to copy from, selecting the substandard sheet, copying the
>> >> > information from the sheet and choosing paste special to the master file.
>> >> > This takes forever. The files are all located in K:\fab\fab.xls,
>> >> > K:\csb\csb.xls, K:\bsf\bsf.xls, K:\bag\bag.xls K:\bnp\bnp.xls to be
>> >> > pasted into K:\corp\corp.xls. The sheets to select from within the files is
>> >> > named 'substandard' - all with the same headings. I need to copy starting
>> >> > from cell A6.
>> >> > The sheets all have different amounts of data so I can't set a static range
>> >> > to copy. And I don't know where it will need to be pasted in the master
>> >> > sheet, or in other words the next empty row.
>> >> >
>> >> > I know how to record a macro with the macro writer, but that is about it and
>> >> > since the amount of data varies I am stumped.
>> >> >
>> >> > Any suggestions??
>> >> > Thanks for any help.
>> >> > Marie
>> >>

>>

 
Reply With Quote
 
=?Utf-8?B?TWFyaWU=?=
Guest
Posts: n/a
 
      13th Jan 2007
Yes, the file I want it to pull the data into has a sheet named Substandard.

I changed the cell address in the function back to A1 and changed the code
to include the quotes around "substandard". Now it is stopping at

Set sourceRange = mybook.Worksheets("Substandard").Range("A2:IV" & lrow)

BUT, it copied cell A1 in my CSB file - I have input in other cells it is
not picking up. It didn't pick up anything in by FAB file.

Am I still doing something wrong?

"Ron de Bruin" wrote:

> Hi Marie
>
> Do not change the cell address in the function
>
> And is the sheet where you want to copy to also named Substandard ?
>
> Change all
>
> (Substandard)
>
> To
>
> ("Substandard")
>
>
>
> --
>
> Regards Ron de Bruin
> http://www.rondebruin.nl/tips.htm
>
>
> "Marie" <(E-Mail Removed)> wrote in message news:13F39DCC-0B43-497D-BAAE-(E-Mail Removed)...
> >I set up a couple of dummy files on my C drive to test it. In the files I
> > named a sheet substandard and input some data. I copied the code and
> > anywhere it referred to sheet1 I changed to substandard.
> >
> > In the function I also changed it to A7 instead of A1 - is this right since
> > I want to copy from A7 - because of my headers?
> > What does this function do?
> >
> >
> > I am getting a Runtime error '9': subscript out of range on this line
> >
> > basebook.Worksheets(Substandard).Cells.Clear
> >
> > This is my code:
> >
> > Sub Copy_Files()
> > FileCopy "C:\csb\csb.xls", "C:\Data\csb.xls"
> > FileCopy "C:\fab\fab.xls", "C:\Data\fab.xls"
> > 'Add four more lines
> > End Sub
> >
> > Function LastRow(sh As Worksheet)
> > On Error Resume Next
> > LastRow = sh.Cells.Find(What:="*", _
> > After:=sh.Range("A7"), _
> > Lookat:=xlPart, _
> > LookIn:=xlFormulas, _
> > SearchOrder:=xlByRows, _
> > SearchDirection:=xlPrevious, _
> > MatchCase:=False).Row
> > On Error GoTo 0
> > End Function
> >
> >
> > Sub Example7()
> > Dim basebook As Workbook
> > Dim mybook As Workbook
> > Dim sourceRange As Range
> > Dim destrange As Range
> > Dim rnum As Long
> > Dim lrow As Long
> > Dim SourceRcount As Long
> > Dim FNames As String
> > Dim MyPath As String
> > Dim SaveDriveDir As String
> >
> > SaveDriveDir = CurDir
> > MyPath = "C:\Data"
> > ChDrive MyPath
> > ChDir MyPath
> >
> > FNames = Dir("*.xls")
> > If Len(FNames) = 0 Then
> > MsgBox "No files in the Directory"
> > ChDrive SaveDriveDir
> > ChDir SaveDriveDir
> > Exit Sub
> > End If
> >
> > Application.ScreenUpdating = False
> > Set basebook = ThisWorkbook
> > basebook.Worksheets(Substandard).Cells.Clear
> > ' clear all cells on the first sheet
> > rnum = 1
> >
> > Do While FNames <> ""
> > Set mybook = Workbooks.Open(FNames)
> > lrow = LastRow(mybook.Sheets(Substandard))
> > Set sourceRange = mybook.Worksheets(Substandard).Range("A2:IV" & lrow)
> > 'Copy from A2:IV? (till the last row with data on your sheet)
> > SourceRcount = sourceRange.Rows.Count
> > Set destrange = basebook.Worksheets(Substandard).Cells(rnum, "A")
> >
> > ' sourceRange.Copy destrange
> > ' Instead of this line you can use the code below to copy only the
> > values
> >
> > With sourceRange
> > Set destrange =
> > basebook.Worksheets(Substandard).Cells(rnum, "A"). _
> > Resize(.Rows.Count,
> > .Columns.Count)
> > End With
> > destrange.Value = sourceRange.Value
> >
> > mybook.Close False
> > rnum = rnum + SourceRcount
> > FNames = Dir()
> > Loop
> > ChDrive SaveDriveDir
> > ChDir SaveDriveDir
> > Application.ScreenUpdating = True
> > End Sub
> >
> > Thanks for helping.
> >
> > Marie
> >
> >
> >
> >
> >
> > "Ron de Bruin" wrote:
> >
> >> Hi Marie
> >>
> >> > above are all the files being copied in 'Data'. As I said mine are in
> >> > K:\csb\csb.xls and K:\bag\bag.xls, etc. Six different folders. Do I need to
> >> > create a folder to save them all in for this to work?
> >>
> >> Yes
> >>
> >> I think I will create the C:\Data folder (empty folder) and run this macro first
> >>
> >> Sub Copy_Files()
> >> FileCopy "K:\csb\csb.xls", "C:\Data\csb.xls"
> >> FileCopy "K:\bag\bag.xls", "C:\Data\bag.xls"
> >> 'Add four more lines
> >> End Sub
> >>
> >> Then try the sub from my site (copy the lastrow function also in the module)
> >> You can change C:\Data to any folder
> >>
> >> After the macro is ready you can use Kill to delete the files in C:\Data
> >>
> >> If you need more help post back
> >>
> >>
> >>
> >> --
> >>
> >> Regards Ron de Bruin
> >> http://www.rondebruin.nl/tips.htm
> >>
> >>
> >> "Marie" <(E-Mail Removed)> wrote in message news:EF911C81-2C22-4EE9-98D8-(E-Mail Removed)...
> >> > Thanks! The site is very helpful!
> >> >
> >> > I think the code I need is 'Copy all cells from the sheet or all cells
> >> > without the header row'
> >> >
> >> > As I said I know some basic VB. I have a couple of questions about the code.
> >> >
> >> > MyPath = "C:\Data"
> >> >
> >> > I assume this is where I place the name of the folder I want to pull the
> >> > data from. Do all the files have to be in the same folder? In the example
> >> > above are all the files being copied in 'Data'. As I said mine are in
> >> > K:\csb\csb.xls and K:\bag\bag.xls, etc. Six different folders. Do I need to
> >> > create a folder to save them all in for this to work? They all have a sheet
> >> > that I want to copy with the same name but the files are all in different
> >> > folders.
> >> >
> >> > And this line 'Copy from A2:IV? (till the last row with data on your sheet)
> >> >
> >> > Is the IV like a wildcard? Does it copy everything on the sheet?
> >> >
> >> > Thanks for your patience. I really appreciate it!
> >> >
> >> > Marie
> >> >
> >> >
> >> >
> >> >
> >> > "Ron de Bruin" wrote:
> >> >
> >> >> You can start here Marie
> >> >> http://www.rondebruin.nl/copy3.htm
> >> >>
> >> >> --
> >> >>
> >> >> Regards Ron de Bruin
> >> >> http://www.rondebruin.nl/tips.htm
> >> >>
> >> >>
> >> >> "Marie" <(E-Mail Removed)> wrote in message news:B900999E-1A25-4565-BF5A-(E-Mail Removed)...
> >> >> >I am working with 6 files. I need to copy the data from a sheet (within each
> >> >> > workbook/file) named 'substandard' and paste the information into the
> >> >> > 'substandard' sheet in the master file. To do this I have been opening the
> >> >> > master file, placing the cursor where I want the information, opening the
> >> >> > file I wish to copy from, selecting the substandard sheet, copying the
> >> >> > information from the sheet and choosing paste special to the master file.
> >> >> > This takes forever. The files are all located in K:\fab\fab.xls,
> >> >> > K:\csb\csb.xls, K:\bsf\bsf.xls, K:\bag\bag.xls K:\bnp\bnp.xls to be
> >> >> > pasted into K:\corp\corp.xls. The sheets to select from within the files is
> >> >> > named 'substandard' - all with the same headings. I need to copy starting
> >> >> > from cell A6.
> >> >> > The sheets all have different amounts of data so I can't set a static range
> >> >> > to copy. And I don't know where it will need to be pasted in the master
> >> >> > sheet, or in other words the next empty row.
> >> >> >
> >> >> > I know how to record a macro with the macro writer, but that is about it and
> >> >> > since the amount of data varies I am stumped.
> >> >> >
> >> >> > Any suggestions??
> >> >> > Thanks for any help.
> >> >> > Marie
> >> >>
> >>

>

 
Reply With Quote
 
Ron de Bruin
Guest
Posts: n/a
 
      13th Jan 2007
Hi Marie

Send me your test file private then I look at it for you then


--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Marie" <(E-Mail Removed)> wrote in message news:6874BE78-8CE7-4DA7-9468-(E-Mail Removed)...
> Yes, the file I want it to pull the data into has a sheet named Substandard.
>
> I changed the cell address in the function back to A1 and changed the code
> to include the quotes around "substandard". Now it is stopping at
>
> Set sourceRange = mybook.Worksheets("Substandard").Range("A2:IV" & lrow)
>
> BUT, it copied cell A1 in my CSB file - I have input in other cells it is
> not picking up. It didn't pick up anything in by FAB file.
>
> Am I still doing something wrong?
>
> "Ron de Bruin" wrote:
>
>> Hi Marie
>>
>> Do not change the cell address in the function
>>
>> And is the sheet where you want to copy to also named Substandard ?
>>
>> Change all
>>
>> (Substandard)
>>
>> To
>>
>> ("Substandard")
>>
>>
>>
>> --
>>
>> Regards Ron de Bruin
>> http://www.rondebruin.nl/tips.htm
>>
>>
>> "Marie" <(E-Mail Removed)> wrote in message news:13F39DCC-0B43-497D-BAAE-(E-Mail Removed)...
>> >I set up a couple of dummy files on my C drive to test it. In the files I
>> > named a sheet substandard and input some data. I copied the code and
>> > anywhere it referred to sheet1 I changed to substandard.
>> >
>> > In the function I also changed it to A7 instead of A1 - is this right since
>> > I want to copy from A7 - because of my headers?
>> > What does this function do?
>> >
>> >
>> > I am getting a Runtime error '9': subscript out of range on this line
>> >
>> > basebook.Worksheets(Substandard).Cells.Clear
>> >
>> > This is my code:
>> >
>> > Sub Copy_Files()
>> > FileCopy "C:\csb\csb.xls", "C:\Data\csb.xls"
>> > FileCopy "C:\fab\fab.xls", "C:\Data\fab.xls"
>> > 'Add four more lines
>> > End Sub
>> >
>> > Function LastRow(sh As Worksheet)
>> > On Error Resume Next
>> > LastRow = sh.Cells.Find(What:="*", _
>> > After:=sh.Range("A7"), _
>> > Lookat:=xlPart, _
>> > LookIn:=xlFormulas, _
>> > SearchOrder:=xlByRows, _
>> > SearchDirection:=xlPrevious, _
>> > MatchCase:=False).Row
>> > On Error GoTo 0
>> > End Function
>> >
>> >
>> > Sub Example7()
>> > Dim basebook As Workbook
>> > Dim mybook As Workbook
>> > Dim sourceRange As Range
>> > Dim destrange As Range
>> > Dim rnum As Long
>> > Dim lrow As Long
>> > Dim SourceRcount As Long
>> > Dim FNames As String
>> > Dim MyPath As String
>> > Dim SaveDriveDir As String
>> >
>> > SaveDriveDir = CurDir
>> > MyPath = "C:\Data"
>> > ChDrive MyPath
>> > ChDir MyPath
>> >
>> > FNames = Dir("*.xls")
>> > If Len(FNames) = 0 Then
>> > MsgBox "No files in the Directory"
>> > ChDrive SaveDriveDir
>> > ChDir SaveDriveDir
>> > Exit Sub
>> > End If
>> >
>> > Application.ScreenUpdating = False
>> > Set basebook = ThisWorkbook
>> > basebook.Worksheets(Substandard).Cells.Clear
>> > ' clear all cells on the first sheet
>> > rnum = 1
>> >
>> > Do While FNames <> ""
>> > Set mybook = Workbooks.Open(FNames)
>> > lrow = LastRow(mybook.Sheets(Substandard))
>> > Set sourceRange = mybook.Worksheets(Substandard).Range("A2:IV" & lrow)
>> > 'Copy from A2:IV? (till the last row with data on your sheet)
>> > SourceRcount = sourceRange.Rows.Count
>> > Set destrange = basebook.Worksheets(Substandard).Cells(rnum, "A")
>> >
>> > ' sourceRange.Copy destrange
>> > ' Instead of this line you can use the code below to copy only the
>> > values
>> >
>> > With sourceRange
>> > Set destrange =
>> > basebook.Worksheets(Substandard).Cells(rnum, "A"). _
>> > Resize(.Rows.Count,
>> > .Columns.Count)
>> > End With
>> > destrange.Value = sourceRange.Value
>> >
>> > mybook.Close False
>> > rnum = rnum + SourceRcount
>> > FNames = Dir()
>> > Loop
>> > ChDrive SaveDriveDir
>> > ChDir SaveDriveDir
>> > Application.ScreenUpdating = True
>> > End Sub
>> >
>> > Thanks for helping.
>> >
>> > Marie
>> >
>> >
>> >
>> >
>> >
>> > "Ron de Bruin" wrote:
>> >
>> >> Hi Marie
>> >>
>> >> > above are all the files being copied in 'Data'. As I said mine are in
>> >> > K:\csb\csb.xls and K:\bag\bag.xls, etc. Six different folders. Do I need to
>> >> > create a folder to save them all in for this to work?
>> >>
>> >> Yes
>> >>
>> >> I think I will create the C:\Data folder (empty folder) and run this macro first
>> >>
>> >> Sub Copy_Files()
>> >> FileCopy "K:\csb\csb.xls", "C:\Data\csb.xls"
>> >> FileCopy "K:\bag\bag.xls", "C:\Data\bag.xls"
>> >> 'Add four more lines
>> >> End Sub
>> >>
>> >> Then try the sub from my site (copy the lastrow function also in the module)
>> >> You can change C:\Data to any folder
>> >>
>> >> After the macro is ready you can use Kill to delete the files in C:\Data
>> >>
>> >> If you need more help post back
>> >>
>> >>
>> >>
>> >> --
>> >>
>> >> Regards Ron de Bruin
>> >> http://www.rondebruin.nl/tips.htm
>> >>
>> >>
>> >> "Marie" <(E-Mail Removed)> wrote in message news:EF911C81-2C22-4EE9-98D8-(E-Mail Removed)...
>> >> > Thanks! The site is very helpful!
>> >> >
>> >> > I think the code I need is 'Copy all cells from the sheet or all cells
>> >> > without the header row'
>> >> >
>> >> > As I said I know some basic VB. I have a couple of questions about the code.
>> >> >
>> >> > MyPath = "C:\Data"
>> >> >
>> >> > I assume this is where I place the name of the folder I want to pull the
>> >> > data from. Do all the files have to be in the same folder? In the example
>> >> > above are all the files being copied in 'Data'. As I said mine are in
>> >> > K:\csb\csb.xls and K:\bag\bag.xls, etc. Six different folders. Do I need to
>> >> > create a folder to save them all in for this to work? They all have a sheet
>> >> > that I want to copy with the same name but the files are all in different
>> >> > folders.
>> >> >
>> >> > And this line 'Copy from A2:IV? (till the last row with data on your sheet)
>> >> >
>> >> > Is the IV like a wildcard? Does it copy everything on the sheet?
>> >> >
>> >> > Thanks for your patience. I really appreciate it!
>> >> >
>> >> > Marie
>> >> >
>> >> >
>> >> >
>> >> >
>> >> > "Ron de Bruin" wrote:
>> >> >
>> >> >> You can start here Marie
>> >> >> http://www.rondebruin.nl/copy3.htm
>> >> >>
>> >> >> --
>> >> >>
>> >> >> Regards Ron de Bruin
>> >> >> http://www.rondebruin.nl/tips.htm
>> >> >>
>> >> >>
>> >> >> "Marie" <(E-Mail Removed)> wrote in message news:B900999E-1A25-4565-BF5A-(E-Mail Removed)...
>> >> >> >I am working with 6 files. I need to copy the data from a sheet (within each
>> >> >> > workbook/file) named 'substandard' and paste the information into the
>> >> >> > 'substandard' sheet in the master file. To do this I have been opening the
>> >> >> > master file, placing the cursor where I want the information, opening the
>> >> >> > file I wish to copy from, selecting the substandard sheet, copying the
>> >> >> > information from the sheet and choosing paste special to the master file.
>> >> >> > This takes forever. The files are all located in K:\fab\fab.xls,
>> >> >> > K:\csb\csb.xls, K:\bsf\bsf.xls, K:\bag\bag.xls K:\bnp\bnp.xls to be
>> >> >> > pasted into K:\corp\corp.xls. The sheets to select from within the files is
>> >> >> > named 'substandard' - all with the same headings. I need to copy starting
>> >> >> > from cell A6.
>> >> >> > The sheets all have different amounts of data so I can't set a static range
>> >> >> > to copy. And I don't know where it will need to be pasted in the master
>> >> >> > sheet, or in other words the next empty row.
>> >> >> >
>> >> >> > I know how to record a macro with the macro writer, but that is about it and
>> >> >> > since the amount of data varies I am stumped.
>> >> >> >
>> >> >> > Any suggestions??
>> >> >> > Thanks for any help.
>> >> >> > Marie
>> >> >>
>> >>

>>

 
Reply With Quote
 
=?Utf-8?B?TWFyaWU=?=
Guest
Posts: n/a
 
      13th Jan 2007
Just sent the files. Thanks
Marie

"Ron de Bruin" wrote:

> Hi Marie
>
> Send me your test file private then I look at it for you then
>
>
> --
>
> Regards Ron de Bruin
> http://www.rondebruin.nl/tips.htm
>
>
> "Marie" <(E-Mail Removed)> wrote in message news:6874BE78-8CE7-4DA7-9468-(E-Mail Removed)...
> > Yes, the file I want it to pull the data into has a sheet named Substandard.
> >
> > I changed the cell address in the function back to A1 and changed the code
> > to include the quotes around "substandard". Now it is stopping at
> >
> > Set sourceRange = mybook.Worksheets("Substandard").Range("A2:IV" & lrow)
> >
> > BUT, it copied cell A1 in my CSB file - I have input in other cells it is
> > not picking up. It didn't pick up anything in by FAB file.
> >
> > Am I still doing something wrong?
> >
> > "Ron de Bruin" wrote:
> >
> >> Hi Marie
> >>
> >> Do not change the cell address in the function
> >>
> >> And is the sheet where you want to copy to also named Substandard ?
> >>
> >> Change all
> >>
> >> (Substandard)
> >>
> >> To
> >>
> >> ("Substandard")
> >>
> >>
> >>
> >> --
> >>
> >> Regards Ron de Bruin
> >> http://www.rondebruin.nl/tips.htm
> >>
> >>
> >> "Marie" <(E-Mail Removed)> wrote in message news:13F39DCC-0B43-497D-BAAE-(E-Mail Removed)...
> >> >I set up a couple of dummy files on my C drive to test it. In the files I
> >> > named a sheet substandard and input some data. I copied the code and
> >> > anywhere it referred to sheet1 I changed to substandard.
> >> >
> >> > In the function I also changed it to A7 instead of A1 - is this right since
> >> > I want to copy from A7 - because of my headers?
> >> > What does this function do?
> >> >
> >> >
> >> > I am getting a Runtime error '9': subscript out of range on this line
> >> >
> >> > basebook.Worksheets(Substandard).Cells.Clear
> >> >
> >> > This is my code:
> >> >
> >> > Sub Copy_Files()
> >> > FileCopy "C:\csb\csb.xls", "C:\Data\csb.xls"
> >> > FileCopy "C:\fab\fab.xls", "C:\Data\fab.xls"
> >> > 'Add four more lines
> >> > End Sub
> >> >
> >> > Function LastRow(sh As Worksheet)
> >> > On Error Resume Next
> >> > LastRow = sh.Cells.Find(What:="*", _
> >> > After:=sh.Range("A7"), _
> >> > Lookat:=xlPart, _
> >> > LookIn:=xlFormulas, _
> >> > SearchOrder:=xlByRows, _
> >> > SearchDirection:=xlPrevious, _
> >> > MatchCase:=False).Row
> >> > On Error GoTo 0
> >> > End Function
> >> >
> >> >
> >> > Sub Example7()
> >> > Dim basebook As Workbook
> >> > Dim mybook As Workbook
> >> > Dim sourceRange As Range
> >> > Dim destrange As Range
> >> > Dim rnum As Long
> >> > Dim lrow As Long
> >> > Dim SourceRcount As Long
> >> > Dim FNames As String
> >> > Dim MyPath As String
> >> > Dim SaveDriveDir As String
> >> >
> >> > SaveDriveDir = CurDir
> >> > MyPath = "C:\Data"
> >> > ChDrive MyPath
> >> > ChDir MyPath
> >> >
> >> > FNames = Dir("*.xls")
> >> > If Len(FNames) = 0 Then
> >> > MsgBox "No files in the Directory"
> >> > ChDrive SaveDriveDir
> >> > ChDir SaveDriveDir
> >> > Exit Sub
> >> > End If
> >> >
> >> > Application.ScreenUpdating = False
> >> > Set basebook = ThisWorkbook
> >> > basebook.Worksheets(Substandard).Cells.Clear
> >> > ' clear all cells on the first sheet
> >> > rnum = 1
> >> >
> >> > Do While FNames <> ""
> >> > Set mybook = Workbooks.Open(FNames)
> >> > lrow = LastRow(mybook.Sheets(Substandard))
> >> > Set sourceRange = mybook.Worksheets(Substandard).Range("A2:IV" & lrow)
> >> > 'Copy from A2:IV? (till the last row with data on your sheet)
> >> > SourceRcount = sourceRange.Rows.Count
> >> > Set destrange = basebook.Worksheets(Substandard).Cells(rnum, "A")
> >> >
> >> > ' sourceRange.Copy destrange
> >> > ' Instead of this line you can use the code below to copy only the
> >> > values
> >> >
> >> > With sourceRange
> >> > Set destrange =
> >> > basebook.Worksheets(Substandard).Cells(rnum, "A"). _
> >> > Resize(.Rows.Count,
> >> > .Columns.Count)
> >> > End With
> >> > destrange.Value = sourceRange.Value
> >> >
> >> > mybook.Close False
> >> > rnum = rnum + SourceRcount
> >> > FNames = Dir()
> >> > Loop
> >> > ChDrive SaveDriveDir
> >> > ChDir SaveDriveDir
> >> > Application.ScreenUpdating = True
> >> > End Sub
> >> >
> >> > Thanks for helping.
> >> >
> >> > Marie
> >> >
> >> >
> >> >
> >> >
> >> >
> >> > "Ron de Bruin" wrote:
> >> >
> >> >> Hi Marie
> >> >>
> >> >> > above are all the files being copied in 'Data'. As I said mine are in
> >> >> > K:\csb\csb.xls and K:\bag\bag.xls, etc. Six different folders. Do I need to
> >> >> > create a folder to save them all in for this to work?
> >> >>
> >> >> Yes
> >> >>
> >> >> I think I will create the C:\Data folder (empty folder) and run this macro first
> >> >>
> >> >> Sub Copy_Files()
> >> >> FileCopy "K:\csb\csb.xls", "C:\Data\csb.xls"
> >> >> FileCopy "K:\bag\bag.xls", "C:\Data\bag.xls"
> >> >> 'Add four more lines
> >> >> End Sub
> >> >>
> >> >> Then try the sub from my site (copy the lastrow function also in the module)
> >> >> You can change C:\Data to any folder
> >> >>
> >> >> After the macro is ready you can use Kill to delete the files in C:\Data
> >> >>
> >> >> If you need more help post back
> >> >>
> >> >>
> >> >>
> >> >> --
> >> >>
> >> >> Regards Ron de Bruin
> >> >> http://www.rondebruin.nl/tips.htm
> >> >>
> >> >>
> >> >> "Marie" <(E-Mail Removed)> wrote in message news:EF911C81-2C22-4EE9-98D8-(E-Mail Removed)...
> >> >> > Thanks! The site is very helpful!
> >> >> >
> >> >> > I think the code I need is 'Copy all cells from the sheet or all cells
> >> >> > without the header row'
> >> >> >
> >> >> > As I said I know some basic VB. I have a couple of questions about the code.
> >> >> >
> >> >> > MyPath = "C:\Data"
> >> >> >
> >> >> > I assume this is where I place the name of the folder I want to pull the
> >> >> > data from. Do all the files have to be in the same folder? In the example
> >> >> > above are all the files being copied in 'Data'. As I said mine are in
> >> >> > K:\csb\csb.xls and K:\bag\bag.xls, etc. Six different folders. Do I need to
> >> >> > create a folder to save them all in for this to work? They all have a sheet
> >> >> > that I want to copy with the same name but the files are all in different
> >> >> > folders.
> >> >> >
> >> >> > And this line 'Copy from A2:IV? (till the last row with data on your sheet)
> >> >> >
> >> >> > Is the IV like a wildcard? Does it copy everything on the sheet?
> >> >> >
> >> >> > Thanks for your patience. I really appreciate it!
> >> >> >
> >> >> > Marie
> >> >> >
> >> >> >
> >> >> >
> >> >> >
> >> >> > "Ron de Bruin" wrote:
> >> >> >
> >> >> >> You can start here Marie
> >> >> >> http://www.rondebruin.nl/copy3.htm
> >> >> >>
> >> >> >> --
> >> >> >>
> >> >> >> Regards Ron de Bruin
> >> >> >> http://www.rondebruin.nl/tips.htm
> >> >> >>
> >> >> >>
> >> >> >> "Marie" <(E-Mail Removed)> wrote in message news:B900999E-1A25-4565-BF5A-(E-Mail Removed)...
> >> >> >> >I am working with 6 files. I need to copy the data from a sheet (within each
> >> >> >> > workbook/file) named 'substandard' and paste the information into the
> >> >> >> > 'substandard' sheet in the master file. To do this I have been opening the
> >> >> >> > master file, placing the cursor where I want the information, opening the
> >> >> >> > file I wish to copy from, selecting the substandard sheet, copying the
> >> >> >> > information from the sheet and choosing paste special to the master file.
> >> >> >> > This takes forever. The files are all located in K:\fab\fab.xls,
> >> >> >> > K:\csb\csb.xls, K:\bsf\bsf.xls, K:\bag\bag.xls K:\bnp\bnp.xls to be
> >> >> >> > pasted into K:\corp\corp.xls. The sheets to select from within the files is
> >> >> >> > named 'substandard' - all with the same headings. I need to copy starting
> >> >> >> > from cell A6.
> >> >> >> > The sheets all have different amounts of data so I can't set a static range
> >> >> >> > to copy. And I don't know where it will need to be pasted in the master
> >> >> >> > sheet, or in other words the next empty row.
> >> >> >> >
> >> >> >> > I know how to record a macro with the macro writer, but that is about it and
> >> >> >> > since the amount of data varies I am stumped.
> >> >> >> >
> >> >> >> > Any suggestions??
> >> >> >> > Thanks for any help.
> >> >> >> > Marie
> >> >> >>
> >> >>
> >>

>

 
Reply With Quote
 
Ron de Bruin
Guest
Posts: n/a
 
      15th Jan 2007
I have send you the example file
If you need more help let me know


--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Marie" <(E-Mail Removed)> wrote in message news11CE98C-5BE6-4D2D-B6DC-(E-Mail Removed)...
> Just sent the files. Thanks
> Marie
>
> "Ron de Bruin" wrote:
>
>> Hi Marie
>>
>> Send me your test file private then I look at it for you then
>>
>>
>> --
>>
>> Regards Ron de Bruin
>> http://www.rondebruin.nl/tips.htm
>>
>>
>> "Marie" <(E-Mail Removed)> wrote in message news:6874BE78-8CE7-4DA7-9468-(E-Mail Removed)...
>> > Yes, the file I want it to pull the data into has a sheet named Substandard.
>> >
>> > I changed the cell address in the function back to A1 and changed the code
>> > to include the quotes around "substandard". Now it is stopping at
>> >
>> > Set sourceRange = mybook.Worksheets("Substandard").Range("A2:IV" & lrow)
>> >
>> > BUT, it copied cell A1 in my CSB file - I have input in other cells it is
>> > not picking up. It didn't pick up anything in by FAB file.
>> >
>> > Am I still doing something wrong?
>> >
>> > "Ron de Bruin" wrote:
>> >
>> >> Hi Marie
>> >>
>> >> Do not change the cell address in the function
>> >>
>> >> And is the sheet where you want to copy to also named Substandard ?
>> >>
>> >> Change all
>> >>
>> >> (Substandard)
>> >>
>> >> To
>> >>
>> >> ("Substandard")
>> >>
>> >>
>> >>
>> >> --
>> >>
>> >> Regards Ron de Bruin
>> >> http://www.rondebruin.nl/tips.htm
>> >>
>> >>
>> >> "Marie" <(E-Mail Removed)> wrote in message news:13F39DCC-0B43-497D-BAAE-(E-Mail Removed)...
>> >> >I set up a couple of dummy files on my C drive to test it. In the files I
>> >> > named a sheet substandard and input some data. I copied the code and
>> >> > anywhere it referred to sheet1 I changed to substandard.
>> >> >
>> >> > In the function I also changed it to A7 instead of A1 - is this right since
>> >> > I want to copy from A7 - because of my headers?
>> >> > What does this function do?
>> >> >
>> >> >
>> >> > I am getting a Runtime error '9': subscript out of range on this line
>> >> >
>> >> > basebook.Worksheets(Substandard).Cells.Clear
>> >> >
>> >> > This is my code:
>> >> >
>> >> > Sub Copy_Files()
>> >> > FileCopy "C:\csb\csb.xls", "C:\Data\csb.xls"
>> >> > FileCopy "C:\fab\fab.xls", "C:\Data\fab.xls"
>> >> > 'Add four more lines
>> >> > End Sub
>> >> >
>> >> > Function LastRow(sh As Worksheet)
>> >> > On Error Resume Next
>> >> > LastRow = sh.Cells.Find(What:="*", _
>> >> > After:=sh.Range("A7"), _
>> >> > Lookat:=xlPart, _
>> >> > LookIn:=xlFormulas, _
>> >> > SearchOrder:=xlByRows, _
>> >> > SearchDirection:=xlPrevious, _
>> >> > MatchCase:=False).Row
>> >> > On Error GoTo 0
>> >> > End Function
>> >> >
>> >> >
>> >> > Sub Example7()
>> >> > Dim basebook As Workbook
>> >> > Dim mybook As Workbook
>> >> > Dim sourceRange As Range
>> >> > Dim destrange As Range
>> >> > Dim rnum As Long
>> >> > Dim lrow As Long
>> >> > Dim SourceRcount As Long
>> >> > Dim FNames As String
>> >> > Dim MyPath As String
>> >> > Dim SaveDriveDir As String
>> >> >
>> >> > SaveDriveDir = CurDir
>> >> > MyPath = "C:\Data"
>> >> > ChDrive MyPath
>> >> > ChDir MyPath
>> >> >
>> >> > FNames = Dir("*.xls")
>> >> > If Len(FNames) = 0 Then
>> >> > MsgBox "No files in the Directory"
>> >> > ChDrive SaveDriveDir
>> >> > ChDir SaveDriveDir
>> >> > Exit Sub
>> >> > End If
>> >> >
>> >> > Application.ScreenUpdating = False
>> >> > Set basebook = ThisWorkbook
>> >> > basebook.Worksheets(Substandard).Cells.Clear
>> >> > ' clear all cells on the first sheet
>> >> > rnum = 1
>> >> >
>> >> > Do While FNames <> ""
>> >> > Set mybook = Workbooks.Open(FNames)
>> >> > lrow = LastRow(mybook.Sheets(Substandard))
>> >> > Set sourceRange = mybook.Worksheets(Substandard).Range("A2:IV" & lrow)
>> >> > 'Copy from A2:IV? (till the last row with data on your sheet)
>> >> > SourceRcount = sourceRange.Rows.Count
>> >> > Set destrange = basebook.Worksheets(Substandard).Cells(rnum, "A")
>> >> >
>> >> > ' sourceRange.Copy destrange
>> >> > ' Instead of this line you can use the code below to copy only the
>> >> > values
>> >> >
>> >> > With sourceRange
>> >> > Set destrange =
>> >> > basebook.Worksheets(Substandard).Cells(rnum, "A"). _
>> >> > Resize(.Rows.Count,
>> >> > .Columns.Count)
>> >> > End With
>> >> > destrange.Value = sourceRange.Value
>> >> >
>> >> > mybook.Close False
>> >> > rnum = rnum + SourceRcount
>> >> > FNames = Dir()
>> >> > Loop
>> >> > ChDrive SaveDriveDir
>> >> > ChDir SaveDriveDir
>> >> > Application.ScreenUpdating = True
>> >> > End Sub
>> >> >
>> >> > Thanks for helping.
>> >> >
>> >> > Marie
>> >> >
>> >> >
>> >> >
>> >> >
>> >> >
>> >> > "Ron de Bruin" wrote:
>> >> >
>> >> >> Hi Marie
>> >> >>
>> >> >> > above are all the files being copied in 'Data'. As I said mine are in
>> >> >> > K:\csb\csb.xls and K:\bag\bag.xls, etc. Six different folders. Do I need to
>> >> >> > create a folder to save them all in for this to work?
>> >> >>
>> >> >> Yes
>> >> >>
>> >> >> I think I will create the C:\Data folder (empty folder) and run this macro first
>> >> >>
>> >> >> Sub Copy_Files()
>> >> >> FileCopy "K:\csb\csb.xls", "C:\Data\csb.xls"
>> >> >> FileCopy "K:\bag\bag.xls", "C:\Data\bag.xls"
>> >> >> 'Add four more lines
>> >> >> End Sub
>> >> >>
>> >> >> Then try the sub from my site (copy the lastrow function also in the module)
>> >> >> You can change C:\Data to any folder
>> >> >>
>> >> >> After the macro is ready you can use Kill to delete the files in C:\Data
>> >> >>
>> >> >> If you need more help post back
>> >> >>
>> >> >>
>> >> >>
>> >> >> --
>> >> >>
>> >> >> Regards Ron de Bruin
>> >> >> http://www.rondebruin.nl/tips.htm
>> >> >>
>> >> >>
>> >> >> "Marie" <(E-Mail Removed)> wrote in message news:EF911C81-2C22-4EE9-98D8-(E-Mail Removed)...
>> >> >> > Thanks! The site is very helpful!
>> >> >> >
>> >> >> > I think the code I need is 'Copy all cells from the sheet or all cells
>> >> >> > without the header row'
>> >> >> >
>> >> >> > As I said I know some basic VB. I have a couple of questions about the code.
>> >> >> >
>> >> >> > MyPath = "C:\Data"
>> >> >> >
>> >> >> > I assume this is where I place the name of the folder I want to pull the
>> >> >> > data from. Do all the files have to be in the same folder? In the example
>> >> >> > above are all the files being copied in 'Data'. As I said mine are in
>> >> >> > K:\csb\csb.xls and K:\bag\bag.xls, etc. Six different folders. Do I need to
>> >> >> > create a folder to save them all in for this to work? They all have a sheet
>> >> >> > that I want to copy with the same name but the files are all in different
>> >> >> > folders.
>> >> >> >
>> >> >> > And this line 'Copy from A2:IV? (till the last row with data on your sheet)
>> >> >> >
>> >> >> > Is the IV like a wildcard? Does it copy everything on the sheet?
>> >> >> >
>> >> >> > Thanks for your patience. I really appreciate it!
>> >> >> >
>> >> >> > Marie
>> >> >> >
>> >> >> >
>> >> >> >
>> >> >> >
>> >> >> > "Ron de Bruin" wrote:
>> >> >> >
>> >> >> >> You can start here Marie
>> >> >> >> http://www.rondebruin.nl/copy3.htm
>> >> >> >>
>> >> >> >> --
>> >> >> >>
>> >> >> >> Regards Ron de Bruin
>> >> >> >> http://www.rondebruin.nl/tips.htm
>> >> >> >>
>> >> >> >>
>> >> >> >> "Marie" <(E-Mail Removed)> wrote in message news:B900999E-1A25-4565-BF5A-(E-Mail Removed)...
>> >> >> >> >I am working with 6 files. I need to copy the data from a sheet (within each
>> >> >> >> > workbook/file) named 'substandard' and paste the information into the
>> >> >> >> > 'substandard' sheet in the master file. To do this I have been opening the
>> >> >> >> > master file, placing the cursor where I want the information, opening the
>> >> >> >> > file I wish to copy from, selecting the substandard sheet, copying the
>> >> >> >> > information from the sheet and choosing paste special to the master file.
>> >> >> >> > This takes forever. The files are all located in K:\fab\fab.xls,
>> >> >> >> > K:\csb\csb.xls, K:\bsf\bsf.xls, K:\bag\bag.xls K:\bnp\bnp.xls to be
>> >> >> >> > pasted into K:\corp\corp.xls. The sheets to select from within the files is
>> >> >> >> > named 'substandard' - all with the same headings. I need to copy starting
>> >> >> >> > from cell A6.
>> >> >> >> > The sheets all have different amounts of data so I can't set a static range
>> >> >> >> > to copy. And I don't know where it will need to be pasted in the master
>> >> >> >> > sheet, or in other words the next empty row.
>> >> >> >> >
>> >> >> >> > I know how to record a macro with the macro writer, but that is about it and
>> >> >> >> > since the amount of data varies I am stumped.
>> >> >> >> >
>> >> >> >> > Any suggestions??
>> >> >> >> > Thanks for any help.
>> >> >> >> > Marie
>> >> >> >>
>> >> >>
>> >>

>>

 
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
Copy Paste from Class Sheet to Filtered List on Combined Sheet prkhan56@gmail.com Microsoft Excel Programming 6 16th Sep 2008 04:30 PM
Help to code Macro to Copy fron one sheet and paste in other sheet kay Microsoft Excel Programming 3 25th Jul 2008 06:46 PM
Copy from one Sheet and paste on another sheet based on condition Prem Microsoft Excel Misc 2 24th Dec 2007 05:05 AM
Active Cell Copy And Paste Sheet to Sheet =?Utf-8?B?QS5SLkogQWxsYW4gSmVmZmVyeXM=?= Microsoft Excel New Users 4 4th May 2006 02:04 AM
automatic copy and paste from sheet to sheet in a workbook =?Utf-8?B?cmFtc2V5anJhbXNleWo=?= Microsoft Excel Programming 6 11th Dec 2004 12:37 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:10 AM.