Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
646 views
in Technique[技术] by (71.8m points)

excel - VBA code string to cell not working - run time error 1004

I'm trying to accomplish something very simple. Actually it used to run normally but when I changed to windows 7 + Office 2013 it just stopped working.

The following line in VBA won't work:

Worksheets("Charts").Cells(2, 7) = "=" & "23,45" & "/PL!C" & 2

Charts is an existent sheet of mine and PL is another existent sheet.

If I add watch to the right hand side equation I get the following formula, which when pasted to the cell (manually) does work.

=23,45/PL!C2

The error I'm getting is:

Run-time error '1004':
Application-defined or object-defined error

I've looked into several run time error 1004 questions but none of them seem to either be the same issue or work for me. Any ideas ? thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Use the Range.Formula property with EN-US syntax or Range.FormulaLocal property with your regional locale settings.

Worksheets("Charts").Cells(2, 7).FORMULA = "=" & "23.45" & "/PL!C" & 2
Worksheets("Charts").Cells(2, 7).FORMULALOCAL = "=" & "23,45" & "/PL!C" & 2

VBA is very EN-US-centric as providing translation for all regional settings 'on-the-fly' would create a large overhead.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...