Changing Cell Values while Printing

by Allen Wyatt
(last updated May 2, 2015)

6

Madhabi wants to print four copies of a worksheet, but have the value of cell A7 change for each copy. The four values are "Original," "Duplicate," "File," and "Driver." All other data being the same, Madhabi wonders how he can change the text of cell A7 while printing.

One possible approach is to create four different worksheets that contain essentially the same information. Worksheets 2 through 4 could all reference cells on worksheet 1, with the exception of cell A7 which could be set on each worksheet to a different value ("Original," "Duplicate," etc.).

A better approach, however, would be to create a quick macro that you could use for your printing. The macro could handle changing the value of cell A7 just before the worksheet is printed each time. Here's a simple example:

Sub PrintCopies()
    Dim i As Integer
    Dim VList As Variant

    VList = Array("Original", "Duplicate", "File", "Driver")
    For i = LBound(VList) To UBound(VList)
        Range("A7") = VList(i)
        ActiveSheet.PrintOut 
    Next
End Sub

The macro places the four values destined for cell A7 into an array. The macro then steps through each of the four array elements, putting the value into cell A7, and then printing the worksheet. Printing is done to whatever the default printer is on the system.

The macro could easily be assigned to a shortcut key or to the Quick Access Toolbar (as described in other ExcelTips) so that it you could print all four copies quickly.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (9962) applies to Microsoft Excel 2007, 2010, and 2013.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Finding the Last-Used Cell in a Macro

Ever wonder what the macro-oriented equivalent of pressing Ctrl+End is? Here's the code and some caveats on using it.

Discover More

Printing a Document's Mirror Image

If you need to print the mirror image (backwards) of a document, you may think you are out of luck in Word. There are ...

Discover More

Who Has the File Open?

Open a workbook that someone else is working on, and you won't be able to save your changes back into the same file. ...

Discover More

Program Successfully in Excel! John Walkenbach's name is synonymous with excellence in deciphering complex technical topics. With this comprehensive guide, "Mr. Spreadsheet" shows how to maximize your Excel experience using professional spreadsheet application development tips from his own personal bookshelf. Check out Excel 2013 Power Programming with VBA today!

More ExcelTips (ribbon)

Black and White Blues

Getting a chart looking its best on a black-and-white printer can be a challenge. This tip examines different ways you ...

Discover More

Printing a Number of Different Pages

If you don't need to print an entire workbook, it can be confusing to figure out how to print just certain pages. This ...

Discover More

Printing Limited Pages from a Range of Worksheets

Need to print just a few pages from a group of worksheets? The easiest way to handle the task may be through a macro, as ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 0 + 1?

2017-09-11 07:19:33

SYED M.A.

How to print or save these 4 sheet as a Single PDF file , Kindly suggest.

Eagerly waiting for the solution.


2017-07-13 06:26:49

Daniel

that looks very useful.
Allen, I'd like to add to your macro following, maybe you can help:
My worksheet shows "pallet 1 of 20 pallets". I want to print every pallet # twice. I.e. 2x "pallet 1 of 20", 2x "pallet 2 of 20", 2x "pallet 3 of 20" and so on.
Printer shall stop when reaching "pallet 20 of 20".
Thanks in advance for your help!
Daniel


2016-02-26 22:40:37

Rizwan Ahmad

This is very useful tip but i want to do the same but my list contains numeric values like 1 to 20 or the values written in an other worksheet.


2015-05-08 08:53:59

Richard

I use a similar technique where the changed cell is an integer, which drives the a series of look-up formulae for printing a set of invoices.

The changing of the cell value, and the print commands are inside a for next loop.


2015-05-04 01:15:03

avanish

Ref. "Changing Cell Values while Printing"

How can I use it to print multiple worksheet with same data & format.


2015-05-02 12:13:00

Morris

To choose an installed printer add the following line of code before the VList = Array... statement.

Application.Dialogs(xlDialogPrinterSetup).Show


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.