Results 1 to 7 of 7
  1. #1
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    milton keynes, Buckinghamshire
    Posts
    252
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Paste v paste special (2000)

    Can any body tell me why the following code works with paste special as values but not with paste, and has anybody got any ideas as to how I can get it to work with just paste. I have found a work-around but this adds a lot of additional processing to the program.

    Set StandardRow = Range("A6:IU6")
    j = 1
    While MissingStaff(j).StaffNo <> 0
    Range("A6").Activate
    While Val(ActiveCell.Value) < MissingStaff(j).StaffNo
    ActiveCell.Offset(1, 0).Activate
    Wend
    ActiveCell.EntireRow.Insert
    Range(ActiveCell.Address & ":" & ActiveCell.Offset(0, 254).Address).Select
    StandardRow.Copy
    Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
    False, Transpose:=False
    ActiveCell.Value = MissingStaff(j).StaffNo
    ActiveCell.Offset(0, 1).Value = MissingStaff(j).StaffName
    j = j + 1
    Wend

  2. #2
    WS Lounge VIP sdckapr's Avatar
    Join Date
    Jul 2002
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    11,225
    Thanks
    14
    Thanked 342 Times in 335 Posts

    Re: Paste v paste special (2000)

    Try replacing the lines:
    Range(ActiveCell.Address & ":" & ActiveCell.Offset(0, 254).Address).Select
    StandardRow.Copy
    Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
    False, Transpose:=False

    with the single line:
    standardrow.Copy Range(ActiveCell.Address)

    Steve

  3. #3
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    milton keynes, Buckinghamshire
    Posts
    252
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Paste v paste special (2000)

    Steve

    Thanks That worked - but I am baffled as to why.

  4. #4
    WS Lounge VIP sdckapr's Avatar
    Join Date
    Jul 2002
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    11,225
    Thanks
    14
    Thanked 342 Times in 335 Posts

    Re: Paste v paste special (2000)

    There is a PASTESpecial method for ranges, there is NO PASTE method for ranges. It is used in conjuction with the copy method of a range

    The relevant items From the Copy Method HELP (Syntax 2)
    <hr>Copies the Range to the specified range or to the Clipboard.


    expression.Copy(Destination)

    expression Required. An expression that returns an object in the Applies To list.

    Destination Optional Variant. Specifies the new range to which the specified range will be copied. If this argument is omitted, Microsoft Excel copies the range to the Clipboard.<hr>

    You only need a start address, you don't have to give a destination. You also do NOT have to select anything (this actually makes for faster code)
    The line I gave:
    <pre>standardrow.Copy Range(ActiveCell.Address)</pre>

    essentially says "copy the range named standardrow to the activecell (ie range given by activecell's address)"

    Steve

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Paste v paste special (2000)

    Steve,

    Wouldn't standardrow.Copy ActiveCell have the same effect as standardrow.Copy Range(ActiveCell.Address)?

  6. #6
    WS Lounge VIP sdckapr's Avatar
    Join Date
    Jul 2002
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    11,225
    Thanks
    14
    Thanked 342 Times in 335 Posts

    Re: Paste v paste special (2000)

    Yes, I didn't think of this. I was doing air things with the original code and it had the entire start and endcell so when I copy/pasted from the code and did some editing it was simpler. I just didn't think of even more simplification.

    I guess that is why I am NOT a programmer.

    [Though I could say, that this type of procedure is NORMAL for my job. You make an improvement, BUT you don't do it the BEST way, you ALWAYS leave something there (that YOU know about) for LATER improvement when the customer wants the next tweak, this buys time so you can actually work on a real improvment later!]

    Steve

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Paste v paste special (2000)

    That reminds me of the way mathematicians solve problems.

    Problem 1:

    You can use the following:
    - an empty saucepan
    - a cold water tap
    - a gas ring, turned off
    - a box of matches

    Goal:
    - a saucepan full of boiling water.

    Solution: easy!
    - take the saucepan to the tap
    - fill it with cold water
    - put it on the gas ring
    - turn on the gas and light it with a match
    - wait till the water boils

    Problem 2:

    You can use the following:
    - an saucepan filled with warm water
    - a cold water tap
    - a gas ring, turned on
    - a box of matches

    Goal:
    - a saucepan full of boiling water.

    Solution: even easier!
    - throw the water out of the saucepan
    - turn off the gas
    - now, you're in the situation of Problem 1; this problem has already been solved.

Posting Permissions

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