Solved

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

Posted on 2014-01-19
5
385 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
  • 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 42

Accepted Solution

by:
Rob Jurd, EE MVE 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 42

Assisted Solution

by:Rob Jurd, EE MVE
Rob Jurd, EE MVE 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

831 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