title: VBA Function to split comma delimited cell
body: <p>I need to split some data in a Cell that is separated by comma. I know this can be down the the text to column excel function but I need it to be in VBA because this process has to be automatic. I created this function:</p>
  
  <pre><code>Function SepararDatos(splitVal As Variant)
  Dim totalVals As Long
  
  splitVal = Split(splitVal, ",")
  totalVals = UBound(splitVal)
  Range(Cells(ActiveCell.Row, ActiveCell.Column + 1), Cells(ActiveCell.Row, ActiveCell.Column + 1 + totalVals)).Value = splitVal
  End Function
  </code></pre>
  
  <p>but I don't know why it isn't working. If I change it to a <code>sub</code> it works great but it's not what i need. Can someone tell me how to change the function to work. Also the sub returns string but i would like to return number.</p>