Excel VBA - 1004 run-time error, Application or object-defined error

后端 未结 2 650
太阳男子
太阳男子 2021-01-25 08:25

I\'m trying to go through a range of cells in a worksheet and write a formula in each one. But I keep getting the error:

Run-time error \'1004\'

Application-de         


        
相关标签:
2条回答
  • 2021-01-25 08:26

    Error was in the string:

    Worksheets("Rawdata1").Cells(row, col).FormulaR1C1 = "=IF(Numbers1!$E$" & col & "<>0;Numbers1!" & "$" & strColCharacter & "$" & row & ";"""")"
    

    Should have been:

    Worksheets("Rawdata1").Cells(row, col).FormulaR1C1 = "=IF(Numbers1!$E$" & row & "<>0;Numbers1!" & "$" & strColCharacter & "$" & row & ";"""")"
    

    Targeting the row, not the column.

    0 讨论(0)
  • 2021-01-25 08:38

    Your problem is with .FormulaR1C1. This tells the formula to expect a Row Number, Column Number style formula reference, but then you give it an address (Column, Row) style formula.

    Change .FormulaR1C1 to .Formula

    0 讨论(0)
提交回复
热议问题