-7

Vba excel 2013 returning zero when executing rng.value=""

Function Delete_UDF(rng)
    ThisWorkbook.Application.Volatile
    rng.Value = ""
End Function

This is returning zero, anyone knows why?

Community
  • 1
  • 1
David Boyd
  • 1
  • 1
  • 1
  • 3
    This looks more like a **Sub** than a **Function**. But whatever it is, you need to learn the most basic of basics of VBA if you can't get this right. – K.Dᴀᴠɪs Feb 04 '18 at 09:21

2 Answers2

3

Your function does not return anything. You need to add something like:

Delete_UDF = "return value"
Herco
  • 377
  • 2
  • 9
1

Your use of Application.Volatile tells me you are using this UDF on a worksheet and this will never work from the worksheet.

A UDF called from the worksheet cannot change any cell on that worksheet or other worksheet other than returning a value to the cell it is being used on. If you used this in A1 like =Delete_UDF(A1) it would be a circular reference and not work for that reason.

This will never work as a UDF on the worksheet.