Consulting

Results 1 to 5 of 5

Thread: Copy, Paste Special and Insert

  1. #1
    VBAX Newbie
    Joined
    Nov 2010
    Posts
    3
    Location

    Copy, Paste Special and Insert

    Hi,

    I have a unique problem that I have solved half way through.

    My spreadsheet has 2 tabs. The first tab has some info that changes frequently. The second tab is where the revised info needs to be inserted (not pasted) into row 3 to 22.

    So essentially a person goes into tab 1 and enters some info, which is processed through formulas. Then, when they hit a button, the macro will copy cells A10 to A29 and paste special and Insert it into the second tab, starting at A3.

    I got it to paste special but not insert, it writes over anything else posted there.

    Can somebody help?

    Thanks in advance.

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    I think you need to do it in 2 steps
    [VBA] Sheets(1).Range("A10:A29").Copy
    Sheets("Data").Range("A4").Insert Shift:=xlDown
    Sheets("Data").Range("A4").PasteSpecial Paste:=xlPasteValues
    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    VBAX Expert
    Joined
    Aug 2007
    Location
    Windermere, FL, a 'burb in the greater Orlando metro area.
    Posts
    567
    Location
    Malcolm,

    A question for my understanding.

    Am I interpreting your code correctly? The copy grabs all rows from A10 to A29 (19 rows) by the width of the worksheet (all columns out to XFD (if in XL 2007))? And, then, it inserts this rectangular block into the target starting on the row before A4 (so A3, as stipulated). Finally, you paste special > values so we have the resulting data and no formulas. Right?

    Why not resize that block based upon the last column actually used?

    Just wondering.

    Thanks,
    Ron
    Windermere, FL

  4. #4
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Hi Ron
    While there may be an overhead in copying entire rows, for a single operation, I don't think it is significant, If there was an issue, then certainly try limiting the copy/paste as you described.
    PasteSpecial was identified in the question as a requirement
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  5. #5
    VBAX Expert
    Joined
    Aug 2007
    Location
    Windermere, FL, a 'burb in the greater Orlando metro area.
    Posts
    567
    Location
    Malcolm,

    Thanks,
    Ron
    Windermere, FL

Posting Permissions

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