Runtime error 1004 - Application defined or Object Defined error

  • As part of the long piece of code, at the end I have these 3 lines to add a formula and fill down. But for the life of me I cannot make it work. I keep receiving the error. Looks like that weekday function has an issue. But I do need to use this. Will appreciate some help.


    Code
    Range("G1").FormulaR1C1 = "Work Type ID"
        Range("G2").Formula = "=IF(AND(WEEKDAY(C3)< 7, WEEKDAY(C3)> 1),'CStd',IF(WEEKDAY(C3)=7,'CSat','CSun'))"
        Range("G2:G" & Range("F" & Rows.Count).End(xlUp).Row).FillDown
  • Can you manually put that exact formula into G2 and have Excel accept it ?


    If not, correct it then within the formula in the macro double quotes will need to be doubled up.

  • Thanks. good idea. The only difference was that I changed double quotes to single in the VB as I was getting compile error. To get this working back in Excel, I reverted it and it works there. So still no resolution.

  • You didn't read what I wrote...


    within the formula in the macro double quotes will need to be doubled up

    Code
    Range("G2").Formula = "=IF(AND(WEEKDAY(C3)< 7, WEEKDAY(C3)> 1),""CStd"",IF(WEEKDAY(C3)=7,""CSat"",""CSun""))"

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!