-1

I'm trying do some like this

For Each ws In ThisWorkbook.Worksheets
        ws.Activate

        If ws.Name <> "Estatística" Then
                Range("H9").Formula = "=COUNTIF(D9:D308;1)"
        End If
Next ws

But it gives the error "Application defined or object defined error". The same error doesn't happen if a use another formula, like "=SUM(H9:H13)" for example.

Nevallem
  • 11
  • 2
  • Also [VBA code string to cell not working](http://stackoverflow.com/questions/32319125/vba-code-string-to-cell-not-working-run-time-error-1004) and [Different languages issue when inserting formula from VBA](http://stackoverflow.com/questions/35724156/different-languages-issue-when-inserting-formula-from-vba/35724386#35724386). –  May 01 '16 at 19:06

1 Answers1

1

Try:

Range("H9").Formula = "=COUNTIF(D9:D308,1)"
Gary's Student
  • 95,722
  • 10
  • 59
  • 99
  • Thanks! But why doesn't works with ";"? – Nevallem May 01 '16 at 18:46
  • @Nevallem I have noticed that sometimes when *VBA* deposits a formula, it needs to follow the USA formula standard even if you use a different standard for manual formula deposits. – Gary's Student May 01 '16 at 18:50
  • 1
    This would be a much better answer if you didn't suggest *trying* something, and added an explanation of why this is the solution. *Try this* is a suggestion, not an answer. See http://meta.stackexchange.com/questions/196187/is-try-this-bad-practice/196191#196191 – Ken White May 01 '16 at 18:55
  • Thanks for explanation! – Nevallem May 01 '16 at 19:03
  • @KenWhite I agree that it would have been better to use the word "Use" rather than "Try" – Gary's Student May 01 '16 at 19:42
  • It would also be better if you explain why it solves the problem, so that future users learn something when they read the answer. You can [edit] your post to improve it, as I'm sure you know. :-) – Ken White May 01 '16 at 19:51