Macros

M

marijo

How do I create a link to a worksheet using macros? I recorded a macro
while typing in a worksheet, then inserted another worksheet and placed
an object to assign it with an existing macro. I got a warning that
says, Run-time error '9': Subscript out of range. Can someone please
teach me how to fix this?
 
G

Greg Wilson

The error message implies that you referenced a
nonexistent member of a collection. In other words, you
have a reference in your code to a worksheet, shape
object, element in an array or other member of a
collection that does not exist. Most often, this results
from an invalid reference to the object.

You need to look at all references to objects, in
particular worksheets and shape objects to ensure that
their referencing is valid. I'm going to guess that you
selected a shape object (command button, chart, rectangle
etc.) on the worksheet and your recorded code reflected
this as "ActiveSheet.Shapes("CommandButton1").Select" or
something similar. If you run the code from another
worksheet then it becomes the active sheet and there is
probably no "CommandButton1" on this sheet.

If you have difficulty resolving the problem, post your
code and we should be able to fix it.

Regards,
Greg
 
Top