Due to Function
fundamentals which state that you can not change or set sheet cells. You need to delete the row with Range("A2") = x
EDIT Some additional link (which I believe is always useful to provide for those who want to analyse UDF topic): Creating custom functions by Microsoft