0

我一直在寻找这样的宏。

宏抛出 1004 错误,并Columns(l + 1).Insert以黄色突出显示

This selection is not valid

Copy and past areas cannot overlap unless they'er the same size and shape

有 107 行,可能代码正在处理整列而不仅仅是 107 行?不知道如何解决这个问题

谢谢

Sub f()
Application.DisplayAlerts = False
Application.ScreenUpdating = False
On Error GoTo Skipit
HeaderNames = Array("RespID", "Subject", "Tag", "Strengths Comments", "Improvement Comments")
For l = 0 To UBound(HeaderNames)
    Columns(Rows(1).Find(HeaderNames(l), , xlValues, xlWhole).Column).Cut
    Columns(l + 1).Insert
Skipit:
Next
ActiveSheet.UsedRange.Offset(, l).ClearContents
Application.ScreenUpdating = True
Application.DisplayAlerts = True
On Error GoTo 0
End Sub
4

1 回答 1

1

你不能复制和粘贴在同一个地方。这应该工作:

Sub f()
Application.DisplayAlerts = False
Application.ScreenUpdating = False
On Error GoTo Skipit
Dim HeaderNames, l As Long, colFrom As Long

HeaderNames = Array("RespID", "Subject", "Tag", "Strengths Comments", "Improvement Comments")
For l = 0 To UBound(HeaderNames)
    colFrom = Rows(1).Find(HeaderNames(l), , xlValues, xlWhole).Column
    If l + 1 <> colFrom Then Columns(colFrom).Cut: Columns(l + 1).Insert
Skipit:
Next
ActiveSheet.UsedRange.Offset(, l).ClearContents
Application.ScreenUpdating = True
Application.DisplayAlerts = True
On Error GoTo 0
End Sub
于 2013-08-30T07:05:54.690 回答