ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Runtime error 1004 write data to a cell (https://www.excelbanter.com/excel-programming/441680-re-runtime-error-1004-write-data-cell.html)

B Lynn B

Runtime error 1004 write data to a cell
 
I pasted your code directly into a module in a blank workbook and tested it.
I did make one edit, removing the space from "col Val", but I'm assuming that
is not in the code you're actually running, because it errors on calling the
function with the space left in. In my test, it worked just fine.

Do you have any protections set on the sheet? That could cause the error.
If that is the source of the problem, you can solve by setting protection
with UserInterfaceOnly property set to True.

"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



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

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