ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Copy range using offset range value (https://www.excelbanter.com/excel-programming/353501-copy-range-using-offset-range-value.html)

Caroline

Copy range using offset range value
 
Hello,
THe following code works on Excel 2002 but seems to fail on another computer
with Excel 2003

Dim TargetCell1 As Range
Set TargetCell1 = Range("TargetCell1")
Range(TargetCell1, TargetCell1.Offset(Range("MaxNoTerritory").Value, 0)).Copy
Range("TargetDisplayCell1").PasteSpecial Paste:=xlPasteValues,
Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False

The error message is
Run-time error '-2147417848 (80010108)':
Method 'PasteSpecial' of object 'Range' failed

and in the debug the following appears
Range("MaxNoTerritory").Value = Method 'Range' of object'_Global' failed

Can you help?
Thanks in advance
--
caroline

Tom Ogilvy

Copy range using offset range value
 
If the code is in a sheet module and the named ranges don't appear on that
sheet, then you would probably come up with an error. The named ranges
would need to be qualified with a reference to the sheet where they belong.

As far as the code, if it were in a general module, it should work in xl97
to xl2003 if all the same workbook were used in each.

--
Regards,
Tom Ogilvy

"caroline" wrote in message
...
Hello,
THe following code works on Excel 2002 but seems to fail on another

computer
with Excel 2003

Dim TargetCell1 As Range
Set TargetCell1 = Range("TargetCell1")
Range(TargetCell1, TargetCell1.Offset(Range("MaxNoTerritory").Value,

0)).Copy
Range("TargetDisplayCell1").PasteSpecial Paste:=xlPasteValues,
Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False

The error message is
Run-time error '-2147417848 (80010108)':
Method 'PasteSpecial' of object 'Range' failed

and in the debug the following appears
Range("MaxNoTerritory").Value = Method 'Range' of object'_Global' failed

Can you help?
Thanks in advance
--
caroline




Caroline

Copy range using offset range value
 
Thanks Tom. The code is in a general module. We are talking about the same
workbook on two different computers. I cannot explain what is going on.
Thanks anyway for taking the time to answer.

--
caroline


"Tom Ogilvy" wrote:

If the code is in a sheet module and the named ranges don't appear on that
sheet, then you would probably come up with an error. The named ranges
would need to be qualified with a reference to the sheet where they belong.

As far as the code, if it were in a general module, it should work in xl97
to xl2003 if all the same workbook were used in each.

--
Regards,
Tom Ogilvy

"caroline" wrote in message
...
Hello,
THe following code works on Excel 2002 but seems to fail on another

computer
with Excel 2003

Dim TargetCell1 As Range
Set TargetCell1 = Range("TargetCell1")
Range(TargetCell1, TargetCell1.Offset(Range("MaxNoTerritory").Value,

0)).Copy
Range("TargetDisplayCell1").PasteSpecial Paste:=xlPasteValues,
Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False

The error message is
Run-time error '-2147417848 (80010108)':
Method 'PasteSpecial' of object 'Range' failed

and in the debug the following appears
Range("MaxNoTerritory").Value = Method 'Range' of object'_Global' failed

Can you help?
Thanks in advance
--
caroline






All times are GMT +1. The time now is 01:56 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com