Excel VBA粘贴到活动单元的偏移量 [英] Excel VBA paste to offset of activecell

查看:160
本文介绍了Excel VBA粘贴到活动单元的偏移量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在UserForm中有一个代码,用于将粘贴值从一个工作表复制到活动单元格中.

I have a code in UserForm for copy pasting values from one worksheet to active cell.

我想将粘贴复制到活动像元偏移中.偏移粘贴的像元位于左侧1个像元,向上10个像元.

I would like to copy paste to active cell offset. Cell that is in offset to paste in is located 1 cell to the left and 10 cells up.

1)将L67从工作表其他数据"复制到活动单元格中

1) Copy L67 from Worksheet "Other Data" to Active Cell

2)从工作表其他数据"中将Q67复制到活动单元格偏移量(-1,-10)

2) Copy Q67 from Worksheet "Other Data" to Active Cell Offset (-1,-10)

我尝试过的代码:

Private Sub CommandButton2_Click()

'Paste to a Defined Range
ThisWorkbook.Sheets("Other Data").Range("L67").Copy

'Offset Paste (offsets 2 cells down and 1 to the right
ActiveCell.PasteSpecial xlPasteValues

ThisWorkbook.Sheets("Other Data").Range("Q67").Copy
ActiveCell.Offset(-1, -10).PasteSpecial xlPasteValues

End Sub

我收到以下错误消息:

ActiveCell.Offset(-1, -10).PasteSpecial xlPasteValues

推荐答案

您以错误的方式获得了偏移量.第一个数字是行,第二个数字是列,因此它将是:

You've got the offsets the wrong way round. The first number is rows, the second is columns, so it would be:

ActiveCell.Offset(-10, -1).PasteSpecial xlPasteValues

这篇关于Excel VBA粘贴到活动单元的偏移量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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