色分けされたテーブルがあります。各行を循環し、その行のどの列が色付けされているかを表す文字列を返したいと思います。私のアプローチは、循環するセルの垂直範囲を定義し、その範囲内の各セルに対して、循環する水平範囲を定義することでした。表示されるエラーは、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
何かご意見は?
どうもありがとう。