I have a procedure which generates cell range depending on certain criteria. I also have a function which takes a cell range object as input and returns an array. However, if I call the function within a procedure, I get this error. "Compile error: Can't assign to array" Is there something wrong with my syntax? Thanks.
Option Explicit
'Reads a database table from current Active worksheet and paste to output sheet
Function DBReader(DBMarker As Range) As String
Dim arr(5) As String
'Read data
arr(0) = ActiveWorksheet.DBMarker.Value
arr(1) = ActiveWorksheet.DBMarker.Offset(1, 1).Value
arr(2) = ActiveWorksheet.DBMarker.Offset(2, 1).Value
arr(3) = ActiveWorksheet.DBMarker.Offset(0, 2).Value
arr(4) = ActiveWorksheet.DBMarker.Offset(1, 2).Value
arr(5) = ActiveWorksheet.DBMarker.Offset(2, 2).Value
DBReader = arr()
End Function
The procedure is kinda long, so I'll only show relevant lines
Public Sub LogSum()
'Declare variables
...
Dim DBInfo(5) As String 'Stores info from function
...
Set CellDB = bookLOG.Worksheets(j).UsedRange.Find("Ref:", LookIn:=xlValues)
...
DBInfo = DBReader(CellDB) 'Returns Array from function???
...
End Sub
DBReader = arr()doesn't really make sense since you declaredDBReader()to return a string, not an array of strings. Also -- the name ofarrisarr, notarr().