title: How store a range from excel into a Range variable?
body: <p>I am reading some cells of excel using VBA.</p>
  
  <pre><code>Function getData(currentWorksheet as Worksheet, dataStartRow as Integer, _
  dataEndRow as Integer, DataStartCol as Integer, dataEndCol as Integer)
  
      Dim dataTable as Range
      dataTable = currentWorksheet.Range(currentWorksheet.Cells(dataStartRow, _
      dataStartCol), currentWorksheet.Cells(dataEndRow, dataEndCol))
  
      getData = dataTable
  
  EndFunction
  </code></pre>
  
  <p>It throws an error, object variable or with block variable not set. How take this range in a variable? Please guide me.</p>