+ Reply to Thread
Results 1 to 7 of 7

Purpose of Operation:=xlNone and modifying values before pasting

  1. #1
    Registered User
    Join Date
    05-31-2007
    Posts
    49

    Purpose of Operation:=xlNone and modifying values before pasting

    Hi
    Hi

    Can someone explain to me in simple language what is the purpose of following code lines:
    Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False

    Complete code line is as follows:
    (Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False)

    I am copying some values from an excel file and pasting them into the other.

    Is it possible to modify the value before pasting them.
    For example column B has absolute values and when this is copied and pasted into the column B in other sheet the new values should be in % (i.e. all values should be divided by 100)

    hope my questions makes sense...
    Cheers
    J

  2. #2
    Valued Forum Contributor
    Join Date
    09-19-2008
    Location
    It varies ...
    MS-Off Ver
    Office365 - 64bit
    Posts
    862
    Hi - your online help in VBA will have a better explanation, but:

    Selection.PasteSpecial ....
    Paste:=xlPasteValues : i.e. not pasting text or formulae; including or not formats and so on; this is the default.
    Operation:=xlNone : i.e. multiply, divide, add etc whatever is in the range; default again.
    SkipBlanks _ :=False : i.e. whether to paste blanks as well or skip them; default again.
    Transpose:=False : i.e. copying rows to columns or the other way; default again.

    Taking these out of you PasteSpecial command will have no effect as they are all the defaults.

    Hope that helps. MM.
    MatrixMan.
    --------------------------------------
    If this - or any - reply helps you, remember to say thanks by clicking on *Add Reputation.
    If your issue is now resolved, remember to mark as solved - click Thread Tools at top right of thread.

  3. #3
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    Quote Originally Posted by MatrixMan
    Taking these out of you PasteSpecial command will have no effect as they are all the defaults.
    xyz,

    The default for Paste is xlPasteAll, not xlPasteValues

    The default for Operation is xlPasteSpecialOperationNone, not xlNone. By happy coincidence, these happen to have the same value (-4142), but using look-alike enumerations for properties will bite you one day.

    Assuming default values for parameters is bad practice; you were on exactly the right track.
    Entia non sunt multiplicanda sine necessitate

  4. #4
    Registered User
    Join Date
    05-31-2007
    Posts
    49
    Quote Originally Posted by MatrixMan View Post
    Hi - your online help in VBA will have a better explanation, but:

    Selection.PasteSpecial ....
    Paste:=xlPasteValues : i.e. not pasting text or formulae; including or not formats and so on; this is the default.
    Operation:=xlNone : i.e. multiply, divide, add etc whatever is in the range; default again.
    SkipBlanks _ :=False : i.e. whether to paste blanks as well or skip them; default again.
    Transpose:=False : i.e. copying rows to columns or the other way; default again.

    Taking these out of you PasteSpecial command will have no effect as they are all the defaults.

    Hope that helps. MM.
    Many thanks for your reply. Can you please tell me the syntax for performing operation for example say that if i want to divide the value by 100 (to convert into %) what syntax do i write.

    Sorry if this is too basic but i am a complete novice to VBA and do not have a decent book with me at the moment....

  5. #5
    Forum Contributor
    Join Date
    02-23-2006
    Location
    Near London, England
    MS-Off Ver
    Office 2003
    Posts
    770
    An internet search of 'excel vba pastespecial operation' will give you plenty of results. This is from the MSDN.

    XlPasteSpecialOperation
    XlPasteSpecialOperation can be one of these XlPasteSpecialOperation constants.
    xlPasteSpecialOperationAdd
    xlPasteSpecialOperationDivide
    xlPasteSpecialOperationMultiply
    xlPasteSpecialOperationNone default
    xlPasteSpecialOperationSubtract


    This example replaces the data in cells D1:D5 on Sheet1 with the sum of the existing contents and cells C1:C5 on Sheet1.

    Please Login or Register  to view this content.
    So at a guess you have 2 options. Either fill the entire range that you are going to paste to with '100' s, and then use the xlPasteSpecialOperationDivide, or what is probably easier is to just paste the values over as they are, and then run another section of code to divide all the values by 100.

  6. #6
    Registered User
    Join Date
    05-31-2007
    Posts
    49
    Quote Originally Posted by Phil_V View Post
    An internet search of 'excel vba pastespecial operation' will give you plenty of results. This is from the MSDN.



    So at a guess you have 2 options. Either fill the entire range that you are going to paste to with '100' s, and then use the xlPasteSpecialOperationDivide, or what is probably easier is to just paste the values over as they are, and then run another section of code to divide all the values by 100.
    Many thanks for your reply. Can you help me further by a little bit. Sorry if this is too basic but i am a complete novice..

    As you said that first paste the values as they are and then run anotehr section of code to divide all values by 100. What would the code be for this second part i.e. say i have pasted the values in column A and then i need to update the values (such as dividing all by 100) how do i do that.

    Many many thanks for your input and time.

  7. #7
    Forum Contributor
    Join Date
    02-23-2006
    Location
    Near London, England
    MS-Off Ver
    Office 2003
    Posts
    770
    If the values are going straight into columnA, and there's nothing else on that sheet you can do the following.
    Let's say your data in in columnE (5) on sheet1, and you want to copy it to columnA (1) on sheet 2:

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1