Option Explicit
Sub NN_to_N1()
Rem 本程序用于将N*N列矩阵拼接成N^2*1列矩阵
Rem 2019/04/11
Dim i As Long '计数项
Dim Quotient As Long '商
Dim Remainder As Long '余数
Dim arr As Variant '数组
Dim brr As Variant '数组
Dim N As Long '数据的行数
Application.ScreenUpdating = False
arr = Cells(1, 1).CurrentRegion
If UBound(arr, 1) = UBound(arr, 2) Then N = UBound(arr, 1)
ReDim brr(1 To N * N, 1 To 1)
For i = 1 To N * N Step 1
Remainder = i Mod N
Quotient = (i - (i Mod N)) / N
If Remainder = 0 Then
brr(i, 1) = arr(N, Quotient)
Else
brr(i, 1) = arr(Remainder, Quotient + 1)
End If
Next i
Cells(1, UBound(arr, 2) + 2).Resize(UBound(brr, 1), UBound(brr, 2)) = brr
Application.ScreenUpdating = True
MsgBox "ok!"
End Sub