LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default Copying Data Another Try

I want to be able to copy a range of non-continuous cells from one work book
to another one. A colleague of mine has come up with the following code
which eclares the two ranges as arrays. I want to be able to modify the code
so that I can copy about 50 cells from one book to the other - Can anyone
suggest an easier way of doing this?

Option Explicit
'
'

' specify your Source & Destination workbooks & worksheets in this section
' the number of cells to copy -1
' the source & destination cells in the 2 arrays

'Source workbook & sheet
Const SOURCE_Sheet = "Sheet1"
Const SOURCE_Workbook = "book1.xls"

'Destination workbook & sheet
Const DEST_Sheet = "Sheet2"
Const DEST_Workbook = "C:\Shared Documents/book2"
Const SAVE_book = "Book2.xls"

Const CopyCells = 10 'no of cells to copy


Sub Copy()

Dim DataSource 'cell locations of data to move
Dim DataDest 'cell destinations
Dim Data(0 To CopyCells) 'array holding value of data in cells
Dim element As Integer 'array element pointer

Application.ScreenUpdating = False

'location of cells to copy
DataSource = Array("A1", "A2", "A3", "A4", "A5", "A7", "A9", "A11",
"A15", "A19", "A20")
'location of cells to copy into
DataDest = Array("B2", "E2", "D4", "F6", "B6", "A7", "A9", "C11", "C1",
"D1", "E8")


'read data into array
For element = 0 To CopyCells
Data(element) = Worksheets(SOURCE_Sheet).Range(DataSource(element) )
Next element

'Open Destination Workbook at correct sheet NOT in a seperate taskbar
Application.ShowWindowsInTaskbar = False
Workbooks.Open Filename:=DEST_Workbook
Worksheets(DEST_Sheet).Select


'copy data into Destination worksheet
For element = 0 To CopyCells
Worksheets(DEST_Sheet).Range(DataDest(element)) = Data(element)
Next element

'return to Source book
Windows(SOURCE_Workbook).Activate
Workbooks(SAVE_book).Close savechanges:=True

End Sub


 
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
Copying rows of data into new worksheet but placing data into colu Thalarctos Excel Discussion (Misc queries) 0 June 6th 10 04:01 AM
Copying Data Inferno Excel Worksheet Functions 0 December 16th 07 10:23 AM
Copying data as static as source data changes pfrost Excel Worksheet Functions 3 March 13th 06 02:52 PM
Copying Data into Column with Existing Data GZul Excel Discussion (Misc queries) 0 February 9th 06 11:30 PM
Copying data down to next dirty cell, then copying that data slarson Excel Programming 0 September 15th 03 09:19 PM


All times are GMT +1. The time now is 04:26 AM.

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"