Excel VBA:粘贴问题 [英] Excel VBA: Paste problems

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

问题描述

我已经尝试了各种各样的方式来做这个粘贴,但是没有一个工作。我非常新的编程,所以我需要一些帮助,了解为什么我会收到错误1004或5.我甚至不明白这些错误是什么意思。

  Cells(hotcell).Copy 
Cells.Offset(0,1).PasteSpecial

或...粘贴,... PasteSpecial = xlpasteall,... pastespecial粘贴:= xlpasteall,Range(Cells(B& i))粘贴,范围(B & i).paste等等,如上所述。



我有一个完全的损失。程序中的其他一切都正常工作。我无法让它将我的复制的值粘贴到所需的单元格中(所有单元格都被一定数量的列偏移,但在同一行中)。帮助和解释都赞赏。



编辑感谢我收到的两个答案,我能够解决我的问题。我真的找不到一个很好的答案在任何地方我看。谢谢!



我使用的解决方案是最简单的一种:

  rng.Offset(0,1)= rng.Text 

再次感谢那些回覆的海报,以及评论者。我正在做的很困难。

解决方案

有很多方法来处理这种问题,所以我会尝试列出一些我使用的。



不粘贴方法

  Sub CP1()
'这基本上只是传递价值而不用大惊小怪。
Dim Rng As Range
Set Rng = Range(A1)
Rng.Offset(0,1)= Rng.Value
End Sub

简单粘贴方法

  Sub CP2()
'这将完全复制一个单元格。
Dim Rng As Range
设置Rng =范围(A1)
Rng.Copy Rng.Offset(0,1)'读取:将Rng复制到Rng.Offset(0,1) 。
Application.CutCopyMode = False
End Sub

特殊粘贴方法

  Sub CP3()
'仅复制格式。
Dim sRng As Range,tRng As Range
Set sRng = Range(A1)
设置tRng = sRng.Offset(0,1)
sRng.Copy
tRng.PasteSpecial xlPasteFormats
Application.CutCopyMode = False
End Sub

尝试从上面的三个确定你想要的和相应的修改。 ;)



希望这有帮助。


I have tried a variety of ways to do this paste, but none of them are working. I am extremely new to programming, so I need some help with understanding why I keep getting either error 1004 or 5. I don't even understand what these errors mean.

Cells(hotcell).Copy
Cells.Offset(0, 1).PasteSpecial

or ...Paste, ...PasteSpecial = xlpasteall, ...pastespecial Paste:= xlpasteall, Range(Cells("B" & i)).paste, Range("B" & i).paste, and so on as above.

I'm at a total loss. Everything else in the program is working just fine. I just can't get it to paste my copied values into the desired cells (all offset by a certain number of columns, but in the same row). Help and explanation both appreciated.

Edit Thanks to BOTH of the answers I recieved, I was able to solve my problem. I really couldn't find a good answer anywhere I looked. Thank you!

The solution I used was one of the simplest:

rng.Offset(0, 1) = rng.Text

Thanks again to the posters who answered, and the ones who commented. I was making it far too difficult.

解决方案

There are many ways to approach this kind of problem so I'll try to list some of the ones I use.

No-paste approach

Sub CP1()
    'This basically just transfers the value without fuss.
    Dim Rng As Range
    Set Rng = Range("A1")
    Rng.Offset(0,1) = Rng.Value
End Sub

Simple paste approach

Sub CP2()
    'This copies a cell exactly as it is.
    Dim Rng As Range
    Set Rng = Range("A1")
    Rng.Copy Rng.Offset(0,1) 'Read: Copy Rng to Rng.Offset(0,1).
    Application.CutCopyMode = False
End Sub

Special paste approach

Sub CP3()
    'This copies the format only.
    Dim sRng As Range, tRng As Range
    Set sRng = Range("A1")
    Set tRng = sRng.Offset(0, 1)
    sRng.Copy
    tRng.PasteSpecial xlPasteFormats
    Application.CutCopyMode = False
End Sub

Try determining from the three above which it is you want and modify accordingly. ;)

Hope this helps.

这篇关于Excel VBA:粘贴问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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