Solved

How to write a VB script in Excel to copy from a cell range and paste to another while inserting a new row?

Posted on 2006-07-06
3
3,021 Views
Last Modified: 2007-12-19
I am trying to write a VB script that I can assign to a button on a Excel workbook. What I need the script to do is copy a cell range (i.e., a10:l10) and paste it to another area in the same spreadsheet. I also need to clear the copied cells and cause the spreadsheet where I paste the data to automatically insert a new row.  This is for an Excel spreadsheet using Microsoft VB.
0
Comment
Question by:rcjax
[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
3 Comments
 
LVL 9

Accepted Solution

by:
jsemenak earned 500 total points
ID: 17050042
Hi,

Sub Macro1()
    Range("A10:I10").Select
    Selection.Copy
    Range("A16").Select
    ActiveSheet.Paste
    Range("A10:I10").Select
    Application.CutCopyMode = False
    Selection.ClearContents
    Rows("16:16").Select
    Selection.Insert Shift:=xlDown
End Sub

This macro copy A10:I10 to A16 :I16 u can modify target.
0
 
LVL 1

Expert Comment

by:dapcom
ID: 17050048
Try this: (done with the macro recorder)

    Range("A1:C1").Select
    Selection.Copy
    Range("A5").Select
    Selection.Insert Shift:=xlDown
    Range("A1:C1").Delete

This actually does not insert a whole row but move the cells down for the range with only.
It should more or less do what you seek?
0
 
LVL 1

Expert Comment

by:dapcom
ID: 17050055
lol, 1 min too late :)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This is about my first experience with programming Arduino.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

739 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