获取具有所有单元属性的一系列单元格

是否有可能一次性获得具有所有单元格属性的单元格的范围,如值,单元格背景颜色,单元格字体等,然后将其存储在数组中。

而不是迭代遍历范围多次,并获取每个个人属性一次?

例如,这将是意图,但我知道这是行不通的:

Dim cellData() As Variant cellData= Range("A36:W36") Debug.Print cellData(1,1).Value Debug.Print cellData(1,1).Interior.ColorIndex 

谢谢

这里有一些我很快看到是否在正确的道路上:

 Sub addToArray() Dim rng As Range, cel As Range Dim cellAttributes() Dim i As Integer, k As Integer ' We're going to store 2 cells' attributes. We're going to use 3 attributes, hence the next line ReDim cellAttributes(1 To 2, 1 To 3) ' since you want Value, Font, and Color, I chose up to three. Change this if you want more attributes 'The array will be cellAttributes([Cell Address],{value, font, color}) Set rng = Range("A1:A2") i = 1 k = 1 For Each cel In rng cellAttributes(i, k) = cel.Value cellAttributes(i, k + 1) = cel.Font.Name cellAttributes(i, k + 2) = cel.Interior.ColorIndex Debug.Print "Cell " & cel.Address & " has a value of: " & cellAttributes(i, 1) & ", font: " & cellAttributes(i, 2) & " and bg color index: " & cellAttributes(i, 3) i = i + 1 k = 1 Next cel End Sub 

在仔细阅读你的问题之后,你究竟想要做什么? 上面的macros将一次查看每个单元格,然后将属性应用于数组,然后再继续。 当然,你可以把它变得更有活力(我使用了更多的“魔法数字”,比我想象的要多,但是我只是想确保这是(或者不是)你正在寻找的东西)。