You are here:

Excel/How to duplicate automatically

Advertisement


Question
Is there a way to duplicate cells using macro?

Sample:

Before Macro
Column A........Column B
Chevrolet.......2
...................5
...................8
Hyundai.........15
...................20
Subaru..........12
...................25

After Macro
Column A........Column B
Chevrolet.......2
Chevrolet.......5
Chevrolet.......8
Hyundai.........15
Hyundai.........20
Subaru..........12
Subaru..........25

Thanks

Answer
Danny,

Yes as long as this is not a pivottable.  

However, let's assume that Chevrolet is in cell A2.  So select A2 to A8 with A2 as the ActiveCell.  Hit F5 to display the goto dialog.  Select special button and then select blank cells.  Now all the blank cells will be selected with the first blank cell, A3 selected.  

Go to the formula bar and type in

=A2
hold down the control key and hit Enter.

this will fill in all the blank cells will the value above it.

Now select A2:A8 and do a copy, then do a paste Values to replace the formulas with the values displayed.

the =A2 formula in the first blank cell refers to the cell above it and that is done in activecell of the cells selected.  If you are working in another range, then just adjust the formula for the activecell/the cell above that (which should be the value you want in that cell.)



--
Regards,
Tom Ogilvy

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


Tom Ogilvy

Expertise

Selected as an Excel MVP by Microsoft since 1999. Answering Excel questions in Allexperts since its inception in 2001. Able to answer questions on almost all aspects of Excel's internal capabilities. If seeking a VBA solution, please specify that in your question itself so I give you the answer you want. [Excel has weak protection - if you are distributing an application, I don't answer questions on how to protect your project from your users.]

Experience

Extensive experience.

Education/Credentials
Master of Science (MS) degree Operations Research (ORSA)

Awards and Honors
Microsoft MVP in Excel.

©2016 About.com. All rights reserved.