Results 1 to 11 of 11

Return ColorIndex array

Threaded View

  1. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    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
    Last edited by shg; 08-01-2008 at 03:02 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1