我有一个宏根据名称命令一些列。它工作在一个列数较少的文件〜(30)但它现在渲染溢出错误~75列。 (我应该注意,有几个列名为"#",我在数组的末尾放置了#'所以宏将所有列留下'# '在最后,然后我将其删除)。这是代码:
Sub reorder_columns()
'Purpose: reorder the columns into the appropiate file order
Dim rng As Range
Dim i As Long
Dim J As Long
Dim Temp
Dim nams As Variant
Dim F
Dim Dex As Integer
nams = Array("PO Number", "PO Line Number", "Vendor’s ID", "Reseller Name","etc","#")
Set rng = Sheets("output").Range("A1").CurrentRegion
For i = 1 To rng.Columns.Count
For J = i To rng.Columns.Count
For F = 0 To UBound(nams)
If nams(F) = rng(J) Then Dex = F: Exit For
Next F
If F < i Then
'***overflow comes in next line*******************
Temp = rng.Columns(i).Value
rng(i).Resize(rng.Rows.Count) = rng.Columns(J).Value
rng(J).Resize(rng.Rows.Count) = Temp
End If
Next J
Next i
End Sub