|
これでどうでしょう?
Sub test()
Dim i As Integer, j As Long, k As Integer
Dim MyRange As Range, MyFind As Range
Application.ScreenUpdating = False
Call Rows(3).Insert(xlShiftDown)
Set MyRange = Range("C1", Range("IV1").End(xlToLeft)).Offset(2, 0)
MyRange.FormulaR1C1 = _
"=IF(OR(R[-1]C[0]=""×"",R[-1]C[0]=""△""),"""",MAX(R[0]C2:R[0]C[-1])+1)"
k = 3
For i = 2 To Range("IV1").End(xlToLeft).Column
If Cells(2, i).Value = "×" Then
For j = 4 To Range("A65536").End(xlUp).Row
Cells(j, i).Value = ""
Next
Else
Cells(3, i).Value = k
For j = 4 To Range("A65536").End(xlUp).Row
Set MyFind = MyRange.Find(j, , xlValues, xlWhole, , xlPrevious)
If Not MyFind Is Nothing Then
Cells(j, i).Value = MyFind.Offset(-2, 0)
End If
Next
End If
Next
Call Rows(3).Delete(xlShiftUp)
Application.ScreenUpdating = True
End Sub
|
|