我有一张用颜色编码的桌子。我想循环浏览每一行,并返回一个字符串,该字符串表示该行中的哪些列是彩色的。我的方法是定义要循环通过的垂直单元格范围,然后为该范围内的每个单元格定义要循环通过的水平范围。我得到的错误表明 For 变量已在使用中。这是我正在使用的代码:
Public Sub Months()
Dim Tally As String
Dim R1 As Range
Dim R2 As Range
Dim Col As String
Range("A2").Select
Range(Selection, Selection.End(xlDown)).Select
Set R1 = Range(Selection.Address)
For Each cell In R1
cell.Activate
Range(Selection, Selection.End(xlRight)).Select
Set R2 = Range(Selection.Address)
For Each cell In R2
If cell.Interior.ColorIndex > 0 Then
Col = Split(ActiveCell(1).Address(1, 0), "$")(0)
If Tally Is Nothing Then
Set Tally = Col
Else
Set Tally = Tally + ";" + Col
End If
Range("DF" & (ActiveCell.Row)).Select
ActiveCell.Value = Tally
End If
Next
Next
End Sub
有什么想法吗?
非常感谢。