You are here:

Excel/VBA MACRO FOR INSERTING MULTIPLE ROWS

Advertisement


Question
Sir,

I want a macro for inserting sufficient rows in my First File for pasting all data (used range)in a column from another File.
Eg: There is 10 rows in Column B in File B (B1 to B10).  I want to copy and past the entire date in Column A (A5-A15) in File A.
Please help me to write a macro to run from File A.
This Macro should do
1) Copy all data in Column B of File B
2) Insert required rows (i.e. 10 rows) after Row "A4" in File A.
3) Paste copied data in Column A of File A ("A5 to A15")

with regards

Varghese Mathew
Kochi, Kerala

Answer
Dear Varghese,

Please use the below code as per the instructions given below:
1. Create 2 files "sourcebook.xslx" and "destinationbook.xslx". These will be your source and destination files for this limited purpose.
2. Enter data in the source file column B.
3. Copy paste the below code in the VB code window of your source file.

Public Sub cpypste()
'count the number of records to be copied
Rng = WorksheetFunction.CountA(Workbooks("sourcebook.xlsx").Worksheets("Sheet1").Range("B:B"))
'select and the data in source file
Windows("sourcebook.xlsx").Activate
Worksheets("Sheet1").Range("B1:B" & Rng).Select
Selection.Copy
'select the destination file
Windows("destinationbook.xlsx").Activate
Range("A5").Select
'insert and paste the copied data
Selection.Insert shift:=xlDown
End Sub

Hope this helps,
Gulshan.
About Excel
This topic answers questions related to Microsoft Excel spreadsheet (or workbook) stand-alone or Mircrosoft Office Excel including Excel 2003, Excel 2007, Office 2000, and Office XP. You can get Excel help on Excel formulas(or functions), Excell macros, charting in Excel, advanced features, and the general use of Excel. This does not provide a general Excel tutorial nor the basics of using a spreadsheet. It provides specific answers to using Microsoft Excel only. If you do not see your Excel question answered in this area then please ask an Excel question here

Excel

All Answers


Answers by Expert:


Ask Experts

Volunteer


GULSHAN PURSWANI

Expertise

I can answer questions related to the following topics: 1. MS Excel - Creating and Linking Formulae, Running Pivot Tables, Vlookup etc. 2. Macros / VBA - Creating Macros to do specific jobs. Importing / Exporting / Validating Data in excel through Macros.

Experience

I've been working on excel for over 10 years and on VBA macros for over 3 years now.

Education/Credentials
Bachelor of Commerce, Chartered Accountant from The Institute of Chartered Accountants of India

©2016 About.com. All rights reserved.