0

I am adding a button in my excel sheet for adding an employee with above used formulas.

First two formulas in the below code work perfect but last one giving syntax error.

My code is :

Private Sub AddEmployee_Click()

    Sheets("Sheet1").Range("A35").Select
    ActiveCell.EntireRow.Insert shift:=xlDown

    Sheets("Sheet1").Range("A35:AJ35").Select
    Selection.Borders.Weight = xlThin

    Sheets("Sheet1").Range("AJ35").Select
    ActiveCell.Formula = "=SpeDays(C35:AG35,9)"

    Sheets("Sheet1").Range("AI35").Select
    ActiveCell.Formula = "=IF(AI35>=10,10,AI35)"

    Sheets("Sheet1").Range("AH35").Select
    ActiveCell.Formula = "=COUNTIF(C35:AG35,">=4000")"
David
  • 354
  • 6
  • 19

2 Answers2

3

The problem are your quotes inside the formula. Use double quotes as a solution:

ActiveCell.Formula = "=COUNTIF(C35:AG35, "">=4000"")"
diiN__________
  • 7,393
  • 6
  • 42
  • 69
1

Use can use the below code as well

Activecell.Formula = "=Countif(C35:AG35," & chr(34) & ">=4000" & chr(34) & ")" 

Output will be:

=Countif(C35:AG35,">=4000")

Mrig
  • 11,612
  • 2
  • 13
  • 27
nishit dey
  • 458
  • 1
  • 7
  • 21