Home » excel » excel vba – error 1004 in vba

excel vba – error 1004 in vba

Posted by: admin May 14, 2020 Leave a comment


Hello I got some code for selecting the nearest value to the user value that is

Private Sub CommandButton1_Click() 
Dim col As Integer 
col = Me.TextBox1.Value
ActiveCell.FormulaR1C1 = "=SMALL($A$1:$EN$1,COUNTIF($A$1:$EN$1,""<" & col & """)+1)"
End Sub 

But i am getting RUNTIME ERROR 1004
anybody help me please

How to&Answers:

You invoke the R1C1-style formula property, but supply an A1-style formula. Try this instead:

ActiveCell.Formula = "=SMALL($A$1:$EN$1,COUNTIF($A$1:$EN$1,""<" & col & """)+1)"

i.e. ActiveCell.Formula instead of ActiveCell.FormulaR1C1.