Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Copying Data Another Try

If there is no pattern, then listing the source cells and the destination
cells would be required and the code shown would just be expanded to list
each in the array.

--
Regards,
Tom Ogilvy

"Gazza" wrote in message
...
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




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default Copying Data Another Try

Appreciate that I need an array but rather than list the cells in the module
would it be possible to list these on say a spare worksheet and have the
code loop through the cells passing the cell reference each time?

Have a feeling that if this was possible it would be easier to set the array
up and make any changes should these arise.

"Tom Ogilvy" wrote in message
...
If there is no pattern, then listing the source cells and the destination
cells would be required and the code shown would just be expanded to list
each in the array.

--
Regards,
Tom Ogilvy

"Gazza" wrote in message
...
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






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Copying Data Another Try

Assume your list of source and corresponding destination cells is on a sheet
named CellList in the workbook containing the code.

Source list starts in A1 and is in column 1 (A)
Destination list starts in B1 and is column 2 (B)

Option Explicit
Option Base 0
'
'

' 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.xls"
Const SAVE_book = "Book2.xls"



Sub Copy()

Dim DataSource 'cell locations of data to move
Dim DataDest 'cell destinations
Dim Data() 'array holding value of data in cells
Dim element As Integer 'array element pointer
Dim rng as Range 'cells holding source list
Dim CopyCells as Long 'no of cells to copy

Application.ScreenUpdating = False

With Worksheets("CellList")
set rng = .Range(.Cells(1,1),.Cells(1,1).End(xldown)).Value
End With

CopyCells = rng.rows.count

Redim Data(1 to CopyCells)

'location of cells to copy
DataSource = rng.Value

'location of cells to copy into
DataDest = rng.offset(0,1).Value

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

'Open Destination Workbook at correct sheet
'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,1)) = Data(element)
Next element

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

End Sub

--
Regards,
Tom Ogilvy


"Gazza" wrote in message
...
Appreciate that I need an array but rather than list the cells in the

module
would it be possible to list these on say a spare worksheet and have the
code loop through the cells passing the cell reference each time?

Have a feeling that if this was possible it would be easier to set the

array
up and make any changes should these arise.

"Tom Ogilvy" wrote in message
...
If there is no pattern, then listing the source cells and the

destination
cells would be required and the code shown would just be expanded to

list
each in the array.

--
Regards,
Tom Ogilvy

"Gazza" wrote in message
...
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








  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 145
Default Copying Data Another Try

Very close now.
We are standing by, and learning.

"Gazza" wrote in message
...
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






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
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 02:55 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"