Solved

i would like to know how do i am using paste specail in excel VBA

Posted on 2014-01-19
5
397 Views
Last Modified: 2014-02-17
i would like to copy from one spreadsheet to another and i would like to know what is the command for copying value and for coping formula

for example i have the following line, how its should be written for each case (for value and for formula)?

wksDest.Range(Cells(rng.Row, 244), Cells(rng.Row, 318)).Copy
               wksSource.Activate
               Cells(lastRow + 1, 107).PasteSpecial xlPasteAll, Paste:=xlPasteCommens

and what is the meaning of .PasteSpecial xlPasteAll

Thanks
Gvilbis
0
Comment
Question by:gvilbis
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 
LVL 27

Assisted Solution

by:MacroShadow
MacroShadow earned 167 total points
ID: 39792515
Sub Demo()
    ' to copy
    wksDest.Range(Cells(Rng.Row, 244), Cells(Rng.Row, 318)).Copy
    ' to paste values
    wksSource.Range(Cells(lastRow + 1, 107)).PasteSpecial xlPasteAll, Paste:=xlPasteValues
    ' to paste formulas
    wksSource.Range(Cells(lastRow + 1, 107)).PasteSpecial xlPasteAll, Paste:=xlPasteFormulas
End Sub

Open in new window


Paste is the argument which determines what part of the range will be copied. The options are:
xlPasteAll - Everything will be pasted.
xlPasteAllExceptBorders - Everything except borders will be pasted.
xlPasteAllMergingConditionalFormats - Everything will be pasted and conditional formats will be merged.
xlPasteAllUsingSourceTheme - Everything will be pasted using the source theme.
xlPasteColumnWidths - Copied column width is pasted.
xlPasteComments - Comments are pasted.
xlPasteFormats - Copied source format is pasted.
xlPasteFormulas - Formulas are pasted.
xlPasteFormulasAndNumberFormats - Formulas and Number formats are pasted.
xlPasteValidation - Validations are pasted.
xlPasteValues - Values are pasted.
xlPasteValuesAndNumberFormats - Values and Number formats are pasted.
0
 

Author Comment

by:gvilbis
ID: 39792626
what is the default of pasting if not mention Paste:=xlPasteFormulasvalues or Paste:=xlPasteValues?

Thanks
Gvilbis
0
 
LVL 43

Accepted Solution

by:
Rob earned 333 total points
ID: 39792806
You can also find out about what's required or default by using the inspector (F2) in the VBA editor.  As you can see below, xlPasteAll is the default as defined by the function

vba editor / inspector
0
 
LVL 43

Assisted Solution

by:Rob
Rob earned 333 total points
ID: 39792812
As MacroShadow has indicated xlPasteAll will copy all formatting, formulas and values from the range you have selected to copy.

It may give you a better idea about what's happening by just performing a paste special via the ribbon

ie

paste special options
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa‚Ķ

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question