6,210
社区成员
发帖
与我相关
我的任务
分享
Function LineToColumn(originalRange As Range) As Variant
Dim i, j, n As Long
n = 0
Dim result()
Dim CallerRows, CallerCols As Long
With Application.Caller
CallerRows = .Rows.Count
CallerCols = .Columns.Count
End With
If CallerCols < 2 Then
MsgBox "too little columns"
Exit Function
End If
ReDim result(1 To CallerRows, 1 To CallerCols)
For i = 1 To originalRange.Rows.Count
For j = 2 To originalRange.Columns.Count
If IsEmpty(originalRange.Cells(i, j)) Then
Exit For
End If
n = n + 1
If n > CallerRows Then
GoTo lastline
End If
result(n, 1) = originalRange.Cells(i, 1)
result(n, 2) = originalRange.Cells(i, j)
Next j
Next i
lastline:
LineToColumn = result
End Function