I am reading some cells of excel using VBA.
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
It throws an error, object variable or with block variable not set. How take this range in a variable? Please guide me.
When you use a
Rangeobject, you cannot simply use the following syntax:You must use the
setkeyword to assign Range objects:Note that every time a range is declared I use the
Setkeyword.You can also allow your
getDatafunction to return aRangeobject instead of aVariantalthough this is unrelated to the problem you are having.