ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Error 1004 (https://www.excelbanter.com/excel-programming/327253-error-1004-a.html)

Tigger

Error 1004
 
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.


Dave Peterson[_5_]

Error 1004
 
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:

Tigger wrote:

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.


--

Dave Peterson

Tigger

Error 1004
 
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!!



All times are GMT +1. The time now is 10:06 AM.

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