View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
B Lynn B B Lynn B is offline
external usenet poster
 
Posts: 131
Default Runtime error 1004 write data to a cell

Maybe we can give better help if you provide more detail around the
conditions under which you get the error. Does the code ALWAYS error
regardless where or how it is run? Are you using the function in a formula
in your spreadsheet? Or are you calling the function through other code?
When you call it, is the active sheet the same one where you want the value
of "sum" to be written?

"Andreas Weber" wrote:

On my function colVal is together, it was a faut on copy the code this
window. But on my system the code doesn't work correct. I have excel 2007 sp2
german version. The worksheet isn't protected. I can't explain this problem
for me. I have tested it on 2 systems win7 and winxp.

Hope you can give me any idee

Greetings

Andreas

"Gary Brown" wrote:

it runs fine for me AFTER I change the col Val to ColVal
--
Hope this helps.
If it does, please click the Yes button.
Thanks in advance for your feedback.
Gary Brown



"Andreas Weber" wrote:

Hello

Always i get an error 1004 on the function above and i can't find my
mistake. I want to read values from the cell an write the steeps in an other
cell. On acces to the cell i get always error 1004.

Option Explicit

Function CalcTest(col Val As Integer, colRes As Integer) As Double
On Error GoTo ErrorHandle

Dim res As Double
Dim sum As Double
Dim i As Long
Dim errNr As Integer

res = 1
sum = 0
For i = 5 To 15
res = Cells(i, colVal).Value 'Read Value
sum = sum + res
Cells(i, colRes).Value = sum 'Write Result, here comes the
error 1004
Next i
CalcTest = sum
Exit Function

ErrorHandle:
errNr = Err.Number
Resume Next

End Function


Thanks for all help, i am very confused about this problem. I need this code
for an other function.

Andreas