Adding Formula from VBA

  • Thread starter Thread starter Anders Eriksson
  • Start date Start date
A

Anders Eriksson

Hello!

I want to add a formula to a cell the formula is:
=TEXT(A1,"dddd")

I have used this code

formel = "=TEXT(A" & CStr(NewRow) & ";""dddd"")"
Worksheets("Blad2").Cells(NewRow, 2).Formula = formel

I get an error on the second line saying:
Runtime Error '1004'
application-defined or object-defined error

NewRow is a valid number, e.g. 36

What is the error?

// Anders
 
What happens when you change the semicolon to a comma?

formel = "=TEXT(A" & CStr(NewRow) & ",""dddd"")"
 
And VBA is very USA centric.

Even if you have the semicolon as your delimiter in your windows regional
settings (so you see that in formulas you type), you'd still use the comma in
your VBA code.
 
What happens when you change the semicolon to a comma?

formel = "=TEXT(A" & CStr(NewRow) & ",""dddd"")"
Work like a charm!

Thank you very much! I would never have thought of this.

// Anders
 
Back
Top