Dear all,
I have some slight knowledge about VBA and writing code.
But this has my mind boggled, and probably it is something really stupid.
I am trying to copy and paste Format and Formulas, from the row above.
By the push of a button.
The formulas should be 'dynamic', in the way that any cell reference is unique and changed from one line to the next.
But now I get the "Run-time error '1004': Application-defined or object-defined error"
I know it doesn't look all too good, I am in no way a professional in writing VBA, but usually I can make it work.
If someone has an idea about what is going wrong, please, it would make my life a lot easier.
This is just one example, but if this is fixed, I can apply it to other issues I'm having as well.
Thank you all in advance!
Kind regards,
D.
I have some slight knowledge about VBA and writing code.
But this has my mind boggled, and probably it is something really stupid.
I am trying to copy and paste Format and Formulas, from the row above.
By the push of a button.
The formulas should be 'dynamic', in the way that any cell reference is unique and changed from one line to the next.
But now I get the "Run-time error '1004': Application-defined or object-defined error"
VBA Code:
Private Sub CommandButton2_Click()
Dim Frmull As String, frmulll As String
Arow = Range("A2").End(xlDown).Address
Brow = Range("A2").End(xlDown).Row
crow = Brow + 1
Arow = "$A$" & crow
Nrow = "$N$" & crow
therow = "$C$" & crow
Frmull = "=IF(A" & crow & "<>"";IF($D" & crow & "="";0;1);"")"
'below is the formula that I want to paste
frmulll = "=IF(" & Arow & "<>""" + """" + ";" + "IF($D" & crow & "=""" + """" + ";0;1);"""")"
Range("A3:N3").Copy 'this is the format
CRange = Arow & ":" & Nrow
'Range("A" & Lrow & ":N" & Lrow).PasteSpecial Paste:=xlPasteFormats
Range(CRange).PasteSpecial Paste:=xlPasteFormats
'Range("C" & Crow).Select
'ActiveCell.FormulaR1C1 = "=R[-1]C[0]"
'ActiveCell.Formula = "=R[-1]C[0]"
Frmul = Range("C" & Brow).Formula
Range("C" & crow).Select
ActiveCell = frmulll
End Sub
I know it doesn't look all too good, I am in no way a professional in writing VBA, but usually I can make it work.
If someone has an idea about what is going wrong, please, it would make my life a lot easier.
This is just one example, but if this is fixed, I can apply it to other issues I'm having as well.
Thank you all in advance!
Kind regards,
D.