ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Select method failed - Error 400 (https://www.excelbanter.com/excel-programming/448555-select-method-failed-error-400-a.html)

Robert Crandal[_2_]

Select method failed - Error 400
 
The following code generates an error in Line 5

Sheets("APR").Select
Rows("9:9").Select
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
Sheets("Data").Select
Rows("25:25").Select ' Line 5 - Error happens here
Selection.Copy
Sheets("APR").Select
ActiveSheet.Paste

The error code is 400. The error description is "Select method
of Range class failed". I'm not sure why this error is occurring,
especially since the above code was generated by Excel's
"Record Macro" function.

Why would the above code work during "Record Macro",
but it generates an error when I run it from VBA code?
I basically have a button on my "APR" spreadsheet that calls
the above code.

Anybody know what's going on here?




Claus Busch

Select method failed - Error 400
 
Hi Robert,

Am Sat, 6 Apr 2013 13:43:24 -0700 schrieb Robert Crandal:

Sheets("APR").Select
Rows("9:9").Select
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
Sheets("Data").Select
Rows("25:25").Select ' Line 5 - Error happens here
Selection.Copy
Sheets("APR").Select
ActiveSheet.Paste


you only can select on a active sheet. But you can write your code
without "Select" and "Selection".
Try:

Sheets("APR").Rows("9:9").Insert Shift:=xlDown, _
CopyOrigin:=xlFormatFromLeftOrAbove
Sheets("Data").Rows("25:25").Copy _
Sheets("APR").Range("A9")


Regards
Claus Busch
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2

Robert Crandal[_2_]

Select method failed - Error 400
 
"Claus Busch" wrote

you only can select on a active sheet. But you can write your code
without "Select" and "Selection".
Try:

Sheets("APR").Rows("9:9").Insert Shift:=xlDown, _
CopyOrigin:=xlFormatFromLeftOrAbove
Sheets("Data").Rows("25:25").Copy _
Sheets("APR").Range("A9")


Works great. Thanks yet again! 8)





All times are GMT +1. The time now is 07:47 PM.

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