0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

VBAそのままコピペ「コピー」

Last updated at Posted at 2019-07-26

コピペして使う用

単純コピー
Sub Macro1()
    Range("A1").Select
    Selection.Copy
    Range("C2").Select
    ActiveSheet.Paste
End Sub
短縮
Sub Sample2()
    Range("A1").Copy Range("C2")
End Sub
シートまたぎ
Sub Sample3()
    Worksheets("Sheet1").Range("A1").Copy Worksheets("Sheet2").Range("C2")
End Sub

https://www.moug.net/tech/exvba/0050104.html
より

値等コピー
Sub PasteSpacialSample()

    Range("B1").Copy      
    Range("E1").PasteSpecial Paste:=xlPasteValues       
    Range("H1").PasteSpecial Paste:=xlPasteFormats      '-----(3)
    Range("H1").PasteSpecial Paste:=xlPasteColumnWidths '-----(4)
        
    Range("K1").PasteSpecial xlPasteAll, Transpose:=True    '-----(5)
    Range("K1").PasteSpecial xlPasteValues, Transpose:=True '-----(6)
    
    Application.CutCopyMode = False
    
End Sub

設定項目

内容

Object Rangeオブジェクト
Paste 何を貼り付けるかを指定します(下表参照)[省略可能]
Operation 演算して貼り付けの際の演算方法を指定します(下表参照)[省略可能]
SkipBlanks 空白セルを無視する(True)、無視しない(False:既定値)[省略可能]
Transpose 行列を入れ替える(True)、入れ替えない(False:既定値)[省略可能]

●表A「貼り付け」対象と引数「Paste」に使用する定数との対応表
(xlPasteType クラス)

貼り付け対象

すべて xlPasteAll(既定) -4104
数式 xlPasteFormulas -4123
値 xlPasteValues -4163
書式 xlPasteFormats -4122
コメント xlPasteComments -4144
入力規則 xlPasteValidation 6 2002以降(※)
罫線を除く全て xlPasteAllExceptBorders 7
列幅 xlPasteColumnWidths 8 2002以降(※)
数式と数値の書式 xlPasteFormulasAndNumberFormats 11 2002以降
値と数値の書式 xlPasteValuesAndNumberFormats 12 2002以降
コピー元のテーマを使用してすべて貼り付け xlPasteAllUsingSourceTheme 13 2007以降
すべての結合されている条件付き書式 xlPasteAllMergingConditionalFormats 14 2010以降

●表B「演算」方法と引数「Operation」に使用する定数との対応表
(xlPasteSpecialOperation クラス)

演算

しない xlPasteSpecialOperationNone(既定) -4142
加算 xlPasteSpecialOperationAdd 2
減算 xlPasteSpecialOperationSubtract 3
乗算 xlPasteSpecialOperationMultiply 4
除算 xlPasteSpecialOperationDivide 5

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?