View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson[_3_] Dave Peterson[_3_] is offline
external usenet poster
 
Posts: 2,824
Default Looking for faster method for Copy & Paste

Untested, but maybe you could just plop the value in (instead of copy|pasting):

For i = row_min To row_max
Workbooks(CStr(ref_sheet.Cells(i,1))) _
.Worksheets(CStr(ref_sheet.Cells(i, 2))) _
.Range(ref_sheet.Cells(i, 3)).value = ref_sheet.Cells(i, 4).value
Next i

or even:
with ref_sheet
For i = row_min To row_max
Workbooks(.Cells(i,1).value) _
.Worksheets(.Cells(i, 2).value) _
.Range(.Cells(i, 3).value).value = .Cells(i, 4).value
Next i
end with

(why the cstr()'s)

(Watchout for typo's. I composed in the email window.)



David Copp wrote:

Hi,

I have a sheet with references to workbooks, sheets, cell addresses and
values whose values need to be copied to the aforementioned workbook, sheet
and address reference.

Ref_sheet looks something like the following...
workbook worksheet address value
1.xls Sheet1 $A$1 Hello
1.xls Sheet1 $A$2 World
2.xls Sheet1 $J$10 10
2.xls Sheet2 $Z$100 32,000

Current method loops through above rows and copies and pastes each value to
location (i.e. copy "Hello" to book "1.xls", sheet "sheet1" to range
"$A$1").
(Needs to be copy & paste to preserve formatting)

For i = row_min To row_max
ref_sheet.Cells(i, 4).Copy
Destination:=Workbooks(CStr(ref_sheet.Cells(i,
1))).Worksheets(CStr(ref_sheet.Cells(i, 2))).Range(ref_sheet.Cells(i, 3))
Next i

where ref_sheet references above sheet... works well but I think it's a
little slow; averaging about 588 records per second (10,000 records taking
about 17 seconds) on a P4 Celeron 2.4 in Excel 97.
Since any of workbook, sheet and address could change row by row, IMHO, need
to evaluate each book, sheet and address reference. (yuck!)

Any suggestions gratefully appreciated.

Thanks in advance,

David Copp


--

Dave Peterson