Excel 2007: runtime error 1004 writing into cell

L

Lamy

Hi,

I try to write into a cell in Excel 2007 worksheet. This works fine
from a procedure, but it raises an runtime error 1004: application or
object defined error called in a function.

See my code below. The sub runs fine, the function crashes. Whats
wrong?

Thanks for any hint.
Lamy


Option Explicit


Sub ttt()
ThisWorkbook.Sheets(1).Cells(21, 5).Value = 7
End Sub


Function fff() As Double
On Error GoTo Excelisbuggy
ThisWorkbook.Sheets(1).Cells(22, 5).Value = 9 'raising runtime
error 1004 here
fff = 5.6
Exit Function

Excelisbuggy:
Debug.Print Str(Err.Number) + ":" + Err.Description
End Function
 

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

Top