Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default Copy Cell Routine (FAO Tom Ogilvie)

Tom,

The code you kindly supplied to me from an earlier post generates a Run-Time
Error (424) "Object Required"

It stops at the line: Set rng = .Range(.Cells(1, 1), .Cells(1,
1).End(xlDown)).Value


Am I doing something wrong??

Thanks
Gazza

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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Copy Cell Routine (FAO Tom Ogilvie)

With Worksheets("CellList")
Set rng = .Range(.Cells(1, 1), .Cells(1, 1).End(xlDown)).Value
End With

shouldn't have .Value on the end

With Worksheets("CellList")
Set rng = .Range(.Cells(1, 1), .Cells(1, 1).End(xlDown))
End With

--
Regards,
Tom Ogilvy

"Gazza" wrote in message ne

...
Tom,

The code you kindly supplied to me from an earlier post generates a

Run-Time
Error (424) "Object Required"

It stops at the line: Set rng = .Range(.Cells(1, 1), .Cells(1,
1).End(xlDown)).Value


Am I doing something wrong??

Thanks
Gazza

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




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default Copy Cell Routine (FAO Tom Ogilvie)

Tom,

WOW - fast reply have made that change but now get a runtime error (9)
Subscript out of range

STOPPING at line; Worksheets(DEST_Sheet).Range(DataDest(element, 1)) =
Data(element)

(Nearly there I hope)

Thanks agian
Gazza


"Tom Ogilvy" wrote in message
...
With Worksheets("CellList")
Set rng = .Range(.Cells(1, 1), .Cells(1, 1).End(xlDown)).Value
End With

shouldn't have .Value on the end

With Worksheets("CellList")
Set rng = .Range(.Cells(1, 1), .Cells(1, 1).End(xlDown))
End With

--
Regards,
Tom Ogilvy

"Gazza" wrote in message ne

...
Tom,

The code you kindly supplied to me from an earlier post generates a

Run-Time
Error (424) "Object Required"

It stops at the line: Set rng = .Range(.Cells(1, 1), .Cells(1,
1).End(xlDown)).Value


Am I doing something wrong??

Thanks
Gazza

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






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Copy Cell Routine (FAO Tom Ogilvie)

What is the value of the Constant DEST_Sheet. Is that a valid worksheet
name in the activeworkbook?

That seems the most likely cause to me.

--
Regards,
Tom Ogilvy

"Gazza" wrote in message
...
Tom,

WOW - fast reply have made that change but now get a runtime error (9)
Subscript out of range

STOPPING at line; Worksheets(DEST_Sheet).Range(DataDest(element, 1)) =
Data(element)

(Nearly there I hope)

Thanks agian
Gazza


"Tom Ogilvy" wrote in message
...
With Worksheets("CellList")
Set rng = .Range(.Cells(1, 1), .Cells(1, 1).End(xlDown)).Value
End With

shouldn't have .Value on the end

With Worksheets("CellList")
Set rng = .Range(.Cells(1, 1), .Cells(1, 1).End(xlDown))
End With

--
Regards,
Tom Ogilvy

"Gazza" wrote in message ne

...
Tom,

The code you kindly supplied to me from an earlier post generates a

Run-Time
Error (424) "Object Required"

It stops at the line: Set rng = .Range(.Cells(1, 1), .Cells(1,
1).End(xlDown)).Value


Am I doing something wrong??

Thanks
Gazza

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








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
Using a cell in the worksheet as a range in a VBA routine dhstein Excel Discussion (Misc queries) 2 December 4th 08 12:13 AM
Clicking on a cell to execute a routine Mark Excel Programming 2 January 27th 04 12:20 PM
SUB ROUTINE tokirk Excel Programming 1 January 19th 04 02:17 AM
Selecting Active Cell before Text Import Routine Paul Excel Programming 2 November 17th 03 10:01 PM
File Copy Routine Neil[_6_] Excel Programming 1 July 10th 03 01:59 PM


All times are GMT +1. The time now is 12:40 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"