将最后使用的列复制并粘贴到下一个可用列中 [英] Copy and paste last used column into next available column

查看:115
本文介绍了将最后使用的列复制并粘贴到下一个可用列中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这可能已经被回答了,但是我已经搜索过以前的问题,找不到适合我的答案。

I know this has probably already been answered but I have searched through the previous questions and cannot find an answer that works for me.

基本上我有一个excel电子表格这可以根据工作流程每天/每周/每月更新。我需要的是一个宏,它找到最后一个'used'列(Headers在第5行),直接在它的右侧插入一个空白列(我们在最后需要一个总计表)&将最后使用的所有列数据复制到新创建的列中。

Basically I have an excel spreadsheet which can be updated daily/weekly/monthly depending on the workflow. What I need is a macro that finds the last 'used' column(Headers are in row 5), inserts a blank column directly to the right of that - (we have a totals table at the end that needs to move along) & copies the entire last used columns data into that newly created column.

这可能是一个很简单的代码,但我只是刚刚开始使用VBA,希望有人可以帮助!我希望一旦我开始做一些工作,我可以建立我的知识!

It's probably quite a simple code but I've only just started using VBA and hope someone can help!! I'm hoping once I've started doing some bits and pieces I can build up my knowledge!

提前感谢

Emma

推荐答案

从这里:将最后一列与指定行的数据复制到下一个空白列,这里: Excel VBA-使用数据查找最后一列

Sub Test()

    Dim ws As Worksheet

    Set ws = ActiveSheet
    Dim rLastCell As Range
    Dim LastCol As Integer

    Set rLastCell = ws.Cells.Find(What:="*", After:=ws.Cells(1, 1), LookIn:=xlFormulas, LookAt:= _
    xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlPrevious, MatchCase:=False)

    LastCol = rLastCell.Column

    ws.Columns(LastCol).Copy ws.Columns(LastCol + 1)

End Sub

这篇关于将最后使用的列复制并粘贴到下一个可用列中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆