Error 1004

  • Thread starter Thread starter Tigger
  • Start date Start date
T

Tigger

Hi,

Can anyone please help with the following:
1004 Application-defined or object-defined error.

....... lots of code

xstart = "555"
For j = 1 To nump
Debug.Print Worksheets("Sheet2").Cells(j, 1).Value, xstart
Worksheets("Sheet2").Cells(j, 1).Value = xstart

....... lots more code

The debug.print prints the correct values from the spreadsheet and the
program variable. It gives the error on the next line when trying to
set the value.
 
The little snippet of code you pasted worked ok for me (after adding some
declares and initializing variables).

Are you running xl97 and calling the code using a control from the control
toolbox toolbar.

If that's the case, change the .takefocusonclick property to false for that
control. If it doesn't have that property, add this line to the top of your
code:
 
Dave,

Thanks for your reply. I have fixed the problem. Your mention of
'running' the code triggered the solution. This code was originally run
as a VB script. I cut/pasted it into VBA as a FUNCTION - hence I cannot
modify a cell etc. Duh!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top