Error 1004
Hi all,
I am doing programming based on others' work. Many times, after I inserted some code, I got runtime error 1004 and there are many reasons explaining it such as can not use a method of a object (e.g. range). THese problem statements are innocent before. Sometime, I change the inserted code position or change some states like who is active sheet and errors gone. My question what is the real reason and how can I prevent it or make capsule for my code? Clara thank you so much for your help |
Error 1004
|
Error 1004
A common problem is when you select ranges. You can only select ranges on the
activesheet. Another common problem is when you don't fully qualify the range. If your code is behind a worksheet, then any unqualified range belongs to the worksheet that owns the code--not the activesheet. So: Worksheets("Sheet99").select range("a1").select May work in a general module--but will fail if the code is behind a worksheet named Sheet1 (not sheet99). worksheets("sheet99").select worksheets("sheet99").range("a1").select will work in both cases with worksheets("sheet99") .select .range("a1").select end with will also work. But there are very few things that need to be selected in your code. Worksheets("Sheet99").range("a1").value = "hi there" will work without the select's. clara wrote: Hi all, I am doing programming based on others' work. Many times, after I inserted some code, I got runtime error 1004 and there are many reasons explaining it such as can not use a method of a object (e.g. range). THese problem statements are innocent before. Sometime, I change the inserted code position or change some states like who is active sheet and errors gone. My question what is the real reason and how can I prevent it or make capsule for my code? Clara thank you so much for your help -- Dave Peterson |
All times are GMT +1. The time now is 10:46 AM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com