簡體   English   中英

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM