我希望创建代码,通过为其命名,将列的每个元素分组到另一个列中。例如:
Year: colour:
2015 blue
2014 red
2003 yellow
2011 blue
2006 red
如果年份为2015
或2011
,则指定的颜色必须为"蓝色",如果年份为2014
或2006
,则为必须是"红色"。
答案 0 :(得分:0)
假设不会再发生任何事情,我只想写一个解决方案:
Sub test()
Dim c As Range, i As Long
Set c = Cells(1, 4)
For i = Cells(Rows.Count, 1).End(xlUp).Row To 2 Step -1
Do
If Len(c.Value) = 0 Then
c.Value = Cells(i, 2).Value: c.Offset(1).Value = Cells(i, 1).Value: Exit Do
ElseIf c.Value = Cells(i, 2).Value Then
Cells(Cells(Rows.Count, c.Column).End(xlUp).Row + 1, c.Column).Value = Cells(i, 1).Value: Exit Do
Else
Set c = c.Offset(, 1)
End If
Loop Until Len(c.Offset(, -1).Value) = 0
Set c = Cells(1, 4)
Next
End Sub
由于此答案已经过调整,只能解决这个问题,因此需要针对任何不同的问题进行调整......