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,016 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
  • 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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

A short article about a problem I had getting the GPS LocationListener working.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

705 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now