
答案1
Public Function find_1s(source As Range) As Variant()
Dim tmp()
Dim i As Integer, j As Integer
tmp = source.Value
j = LBound(tmp, 2)
For i = LBound(tmp, 2) To UBound(tmp, 2)
If tmp(2, i) = 1 Then
tmp(1, j) = tmp(1, i)
j = j + 1
End If
Next i
For i = j To UBound(tmp, 2)
tmp(1, i) = ""
Next i
find_1s = WorksheetFunction.Transpose(tmp)
End Function
当然,还必须添加很多参数检查......