You could return an array the same size and shape as the range. And if you're learning VBA, a good habit to get into is to declare all variables, which you can enforce by adding Option Explicit at the top of every module. And I wouldn't choose variable names that are the same as VBA key words.
Function CellColor(r As Range) As XlColorIndex()
Dim aCI() As XlColorIndex
Dim cell As Excel.Range
ReDim aCI(r.Row To r.Row + r.Rows.Count - 1, r.Column To r.Column + r.Columns.Count - 1)
For Each cell In r
aCI(cell.Row, cell.Column) = cell.Interior.ColorIndex
Next
CellColor = aCI
End Function
Bookmarks