Tag Archives: Excel

Recently I attended an operating session at my club, where we use car cards created and printed from the “ShipIt!” software package. One of the features of the ShipIt! software is the ability to include a railway logo in the top corner of the car card – which I’ve been dully aware of forever since most of our car cards have a CP Rail logo in the upper corner (since our club models CP). However, the guy that prepares and prints out the car cards has actually started using this feature and adding specific logos to cars for different railroads, and the effect is actually pretty sharp when handling the waybills during operations. Thus I got inspired to see if I could add logos to my car cards which I created in Excel. (See my previous post: Excel Car Cards and Waybills)

With a bit of googling, I found this article on ExcelGuru.ca which was exactly what I was looking for. I suggest giving it a read, as this is exactly the information I followed in order to add the logos to my car cards; although I did tweak a couple things in the middle to combine it with my data lookup functions I described in my earlier post on the subject, the original author of that article (Ken Puls) deserves a lot of credit here.

Step 1: Setting up the Image Data

The first section follows the information from the ExcelGuru article pretty much verbatim. We need a new sheet added to the workbook to contain all of the images. Each row in the image table contains two columns, one with the image name, and the second column containing the image pasted into the cell.

There are basically two ways to go about this: define an image for every railway reporting mark you use in your car cards, or just define each image by itself and add in a separate column to the data sheet to specify the image name for each car card. While the second approach causes you to duplicate some value entries in the data table that drives the car cards, it’s the route I ended up going with so that I could optionally use multiple different images against the same reporting marks in order to display lessee logos on privately owned/leased tank cars and not have to define cells for obscure one-off shortlines and companies that I can’t find logos for.

Note that whatever route you go, every possible value that the data could use *must* be defined in the image table, or you’ll end up with the image cell on the final car card displaying a broken reference. If you define an image for each reporting mark, then each mark must be in the image data sheet, even if there’s no actual for that particular mark. There will just be a blank cell defined for that image. For defining images with names, there should be one “Blank” reference.

Each image doesn’t have to be exactly the same size, but they should all fit into the cell on the car card with at least a pixel or two of white space around the edge or it may actually cut off the card border when printed.

Once the table of images to use has been created, we turn each cell containing an image into a named reference that we can use later.

Highlight the table of cells you created, and then under the “Formulas” tab on the toolbar ribbon, in the “Defined Names” group click on “Create from Selection”. Choose to create names from values in the left column. This will use the names in column A to define a specific name for the corresponding cell in column B that can be used later.

That does it for setting up the image table, now let’s make some use of it.

Step 2: Setting up the Data Cells to drive the Image

The middle bit is where my usage may seem slightly more complicated, as in the example in the article, they link the photo to static text whereas I have yet another layer under this, using VLOOKUP functions (which I got into in detail in my previous post) to retrieve text data from another sheet. However, this really doesn’t affect the instructions much, as really the only difference instead of static text in the “driver” cell, the text is returned by that function.

However I do deviate from the article here a little, so I’ll highlight my steps here. First of course, the new data column is added to the Data sheet to specify the name of the logo image to display on the car card. I skipped creating any data validation on these cells.

Then, I added a new cell on the car card template page, just below (and outside the printed border of) the finished car card to output the image name using the standard VLOOKUP functions. I also want the cards to print properly if no logo image is specified in the data, so it’s wrapped with an IF function that returns “Blank” if no value is returned, so the picture cell displays a proper blank cell instead of “#REF” indicating a bad lookup. The final cell formula for the first car card on the sheet then looks like this, where cell E16 contains the starting car card ID:

Now, select that cell, and use the “Define Name” tool in the “Formulas” tab of the toolbar ribbon to manually set a defined name (e.g. “Car1Picture”) for that cell that will again be referenced later.

Next, click on the Name Manager tool in the same section of the toolbar ribbon. We want to edit the name we created and modify its reference a little. Select the new entry (e.g. “Car1Picture”) and change the “Refers To” from:

='Car Cards'!$A$13

to:

=INDIRECT('Car Cards'!$A$13)

What this does is allow this name to refer not specifically to this cell, but to use the value of this cell to refer to another cell, which will allow us to look up the correct cell in the Images table based on the changing sheet data.

Step 3: Linking and Displaying the Image

The final steps are again pretty much followed exactly as presented in the posting on ExcelGuru.

On the Images sheet, select the *cell* (not the actual image object) for the first image and press Ctrl-C to copy it.

Then on the car card template sheet, select the cell where the logo will go and paste in a picture link. It’s important to pick the correct paste option here. The ExcelGuru article shows how to do it in Excel 2010 (right click in the cell, and from the pop-up menu choose Paste Special > Picture Link (icon at bottom right like a little landscape picture with a chain link in front of it)). In the older Excel 2007, which I have, select the cell, and then under the “Home” tab of the toolbar click on Paste > As Picture > Paste Picture Link. This creates a picture object that displays a view of the linked cell.

Of course the point is for it to change based on the sheet data, and not just display the same picture, so we want to change the reference. Click on the created picture to select it, and in the formula bar change the reference to the named cell (from Step 2) that contains the image name for this car card:

And presto! The car card now has an image that will change based on the data for the car card. The final result looks something like this:

Files

If you’d like to print your own car cards, here’s an almost-blank copy of my Excel template, with just a few sample cars as data examples.

Share this:

Here I will discuss how I created my own car cards and waybills using Microsoft Excel’s spreadsheet software.

Note: this will not be intended to be a detailed tutorial on Excel, or the specific features I’m using; I will show enough to convey how I’m using the feature(s), but for additional details I will refer you to Excel’s documentation or other help sites. It should also be possible to achieve these results using similar tools in other spreadsheet software, but I leave that research to the reader as to how the tools in those softwares may differ from Excel.

Car Cards

The specific design of the car cards and waybills is inspired by the ones we use at the club created and printed using the Ship-It model railroad software. They follow the same dimensions and general form factor, although I have tweaked the design a little to customize it for my own purposes (especially of the shipment waybill insert slips – see below).

On the car card, the car information goes at the top, with the most important information (identifying reporting mark and number) in the central place of prominence. Other descriptive information such as type, colour and length are included below to assist in visually identifying the car. The Notes field may indicate other special features of the car, or usage restrictions (for example, “Paper service only” on boxcars meant for such).

The bottom of the card is designed to fold up and be taped to form a pocket into which the shipment/routing portion of the paper work (waybill) is inserted.

Below we see the Excel sheet I use for printing out my car cards. It took some tweaking to get the column sizes exactly correct, but otherwise looks pretty straightforward. However, under the hood all of the fields are defined with formulas that pull data from another sheet in the workbook. I didn’t want to copy and past page after page after page of hand-coded car cards (and especially the waybills with their vastly higher number of fields and flopped orientation) so I made one template page, and used Excel lookup functions to pull the data from another sheet, so the car data could be tracked and manipulated far easier in a standard grid format, and any arbitrary range selected for actual printing. In this way, car cards for a large fleet of hundreds of cars can easily be created.

You’ll see in the first image above of the car card template sheet, a “Starting ID” cell below the cards (in cell E16, highlighted). I’m going to use the value in this cell to feed into the Excel lookup functions, which will extract data from the actual roster sheet, and populate it into the fields in the car card template for printing.

Below is the actual roster information, contained in another sheet within the same workbook. Way easier to read and keep track of, and much more additional notes and information can be added in further columns to the right; our lookup only needs to deal with the first ten columns. Note in particular the first column with the heading “ID”. This is the value we’re going to lookup, and then populate the date from the other columns in the same row into the template sheet for printing.

Excel has several data lookup functions, and the one we want is the “VLOOKUP” function. The VLOOKUP function scans through a specified range of data, looking for a specific value in a particular column. Once that value is found in the search column, it can return a value from another column in that row. The VLOOKUP function in Excel looks like this:

In my case above, we’re pulling the lookup value (the car ID) out of cell E16, so the reference to that cell is the value. (For the subsequent car cards, we want to pull the next several cars in the data sheet, so the lookup value will be the value of (E16)+1, (E16)+2, etc., so if the starting ID is 1, car cards 1 through 5 will be printed.)

The name of my second sheet with the car data is “Data”, and the data is in columns A through K in that sheet. (The VLOOKUP function will scan the first column trying to find the lookup value.)

The last argument should be set to FALSE as we only want an exact match.

Put that all together, and the lookup for the reporting mark field on the first car card looks like this:

One thing to know about the VLOOKUP function in excel, is that if the returned cell in the data sheet is blank, the VLOOKUP function will display that as a 0 in the display cell. For some fields here, like the Notes and Empty return information, I definitely want the cell to be blank if there’s no data, not rendered as zeroes. To protect that, any cell that’s using a VLOOKUP that you want to allow to be blank will need to be wrapped with an Excel IF function, which looks like this:

=IF ([condition], [value if true], [value if false])

In this case, my condition will be if the value from the lookup function is blank (“”), make the cell blank, otherwise insert the returned value. If I do this for the example cell in the image above, it would end up looking like this:

… which actually looks far more complicated than it is, since the whole lookup function is pasted in there twice.

Waybills

I also used these tools to create my own custom waybill template. This was a lot more work than the car cards simply owing to the sheer number of fields involved in each waybill compared to the car card, and managing to fit 10 of them per sheet as opposed to 5 per sheet for the car cards. However, it was largely a matter of just taking the time and effort to copy and adjust the lookup functions much as above. While there are quite a number more fields to deal with, and more waybills fit onto a page than the car cards, the general method is exactly the same. Just time consuming to do that many fields. But once it’s done, you have a dynamic template that can easily and quickly create and print out hundreds of different waybills.

My waybills are “two-cycle” with each one printed on one side of the paper and having two separate moves (generally an empty move and a loaded move), one of which is visible at a time and rotated (between sessions) in the car card pocket to display the second move when the first move is completed. This required printing the second move upside-down to the first – although Excel doesn’t allow you to set the text orientation in a cell to “upside down”. It does however let you do “up” and “down”, so I just designed the waybills sideways with each half oriented a different way, as seen in the image above.

Two-sided four-cycle waybills can also be created, just more of the same effort to set up the additional fields on the second page, and a bit of playing with the page margins and column positions to find the proper alignment so that when the second page is printed on the reverse of the first, the waybill edges line up properly for cutting them out. I only needed two-cycle bills, so I did not bother with this effort.

You’ll see that my waybill template includes a block code for switching/routing at the very top, as generally this is the most important information required when switching or handling cars – “Where does this go?” and using a routing or block code at the top of the waybill makes it easier to identify the car’s immediate destination. This is reinforced with a colour-coded bar below the block code which matches the block. (I plan on making a chart of the blocks and a system map readily available to operators in the model railroad’s timetable document.)

To make the colour coded bar, I created a series of Conditional Formatting rules to apply a fill colour to this cell based on the text value in the block code cell above/beside it.

Once the waybill template is completed, it’s a matter of playing around in the data grid to create the various shipment information, and then printing them out in the template by adjusting the starting ID/group to fill in the data and print the results. Cut out with scissors, insert into the appropriate car cards, and voilà:

Files

A few people asked if I would share the actual Excel files. Here they are.

Notes: The car cards file is useable as-is by anyone. I cleared out my own roster information so the entire world doesn’t know my inventory, just leaving the first few cars behind to illustrate how the data works. For the waybills file, I actually uploaded my file as-is, including all my data. Consider it a gift to other ACR modelers, and shows how the data works. Note that if you’re adapting the file to your own railway and want to include the colour coded bars that match to the destination block codes, you’ll have to go in and edit all the conditional formatting rules for your own station/block names. Note that this workbook also contains the customer order sheet described in my previous post.

If clicking on the link doesn’t open the file properly, right click and choose “Save As…” from the menu that comes up. (Mac users with a one-button mouse, I believe you hold the “Command” key and click for this menu.)

Update: see also followup post where I add company logos to the cards.