ABCDE
zx c
zx c
zx c
到
ABCDE
zx cz
zx cz
zx cz
所以我想选择一个列,宏将其移动到E列
当前尝试定义一个范围,因此它在不同的工作簿之间不可用。
答案 0 :(得分:0)
当你说"移到E"栏时,我认为你的意思是"复制到E"列。请尝试以下代码
Sub Copy_Col()
Dim lc As Long
With ActiveSheet
lc = .Cells(1, .Columns.Count).End(xlToLeft).Column
Selection.Copy
.Cells(1, lc + 1).PasteSpecial
.Range("A1").Select
End With
Application.CutCopyMode = False
End Sub
由于
Caleeco
答案 1 :(得分:0)
Option explicit
Sub CopyColumn()
Dim LastUnmodifiedColumn as long
' no qualified workbook/worksheet below. Therefore, implicitly refers to whatever book/sheet is active'
Lastunmodifiedcolumn = cells(1, columns.count).end(xltoleft).column + 1
' if you want values only, can assign values directly without using clipboard copy/paste operations'
With selection
.value2 = .offset(0,lastunmodifiedcolumn - .column).value2
'If you want to move and not copy, uncomment next line.'
'.clearcontents
End with
End sub
希望它有效或有帮助。