![](/img/trans.png)
[英]How to copy and paste a column of dynamic data (as values) to another column in VBA?
[英]VBA Copy Column and Paste Values to Last Unmodified Column
ABCDE
zx c
zx c
zx c
至
ABCDE
zx cz
zx cz
zx cz
所以我想選擇一列,宏將其移到E列
當前嘗試定義了一個范圍,因此該范圍在不同的工作簿之間不可用。
當您說“移至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
謝謝
卡里科
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
希望它有用或有幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.