1

I'm new here.

I'm trying to set the formula of a cell to a given string as below, but am getting a run-time error '1004': Application-defined or object-defined error. The cell is on the active sheet and I can set the formula to blank in the immediate window but I cannot set it to the formula below without hitting the error.

Cells(47, i).Formula = "=('sheetName'!$C$105-SUM(OFFSET($C$47,0,0,1," + _
    CStr(i - 3) + ")))/(COLUMN($N$47)-COLUMN(" + _
    CStr(i - 1) + "$47))"

I'm wondering if there is some special character restrictions on the string?

3
  • 2
    something wrong with this part: COLUMN(" + CStr(i - 1) + "$47))" because as I see CStr(i - 1) will return number Commented Feb 12, 2014 at 20:41
  • Nevermind! Rookie-mistake. I have the second use of CStr above sending in a number as a cell reference. I set it to Col_Letter(CLng(i - 1)) instead and it works just fine. Col_Letter is a function which returns the letter value of the column number given. Commented Feb 12, 2014 at 20:51
  • 1
    Thanks simoco, you're absolutely right. Commented Feb 12, 2014 at 20:52

1 Answer 1

2

You are getting an error because of this

COLUMN(" + CStr(i - 1) + "$47))"

The cell address has to be like A1 i.e a Letter and then the Number.

Sign up to request clarification or add additional context in comments.

3 Comments

just added the same comment:)
OH I am sorry. I can delete my answer. You can put that as an answer if you want.
Thanks Siddharth, thanks simoco, that was the problem exactly. I fixed it by using Col_Letter(CLng(i - 1)), which returns the column letter corresponding to the long value given.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.