复制和粘贴活动列与合并单元格的VBA代码 [英] VBA Code to copy and paste active column with merged cells inside

查看:729
本文介绍了复制和粘贴活动列与合并单元格的VBA代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试复制活动列并将其粘贴在它旁边,但代码选择整个工作表,因为它合并了单元格。  Sub CopyPaste()

列(ActiveCell.Column).Selection
Selection.Copy
ActiveCell.Offset(0,1).PasteSpecial Paste:= xlPasteAll

End Sub

你能帮助我添加缺少的代码忽略合并的单元格?

解决方案

这是避免使用另一个原因选择在VBA for Excel中。您的选择将随合并的单元格扩展。您可以尝试以下方式:

  ActiveCell.EntireColumn.Copy ActiveCell.Offset(0,1).EntireColumn 

再次,您应该找到一些方法来避免在代码中指望ActiveCell,并使用一些完全限定的范围。 p>

I'm trying to copy the active column and paste it next to it but the code selects the entire worksheet because it has merged cells in.

Sub CopyPaste()

Columns(ActiveCell.Column).Selection
Selection.Copy
ActiveCell.Offset(0,1).PasteSpecial Paste:=xlPasteAll

End Sub 

Could you please help me adding the missing code to ignore merged cells?

解决方案

This is yet another reason to avoid using Select in VBA for Excel. Your selection will expand with the merged cells. You can try this:

ActiveCell.EntireColumn.Copy ActiveCell.Offset(0, 1).EntireColumn

And again, you should find some way to avoid counting on the ActiveCell in your code, and use some fully qualified range.

这篇关于复制和粘贴活动列与合并单元格的VBA代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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