Pixels in a Text String

Written by Allen Wyatt (last updated July 1, 2023)
This tip applies to Excel 97, 2000, 2002, and 2003


Jerrold knows that the LEN function returns the number of characters in a text string. What he needs to know, however, is the number of pixels (not characters) in a text string. He wonders if there is some way to calculate the value.

The short answer is no, there isn't. The longer answer is that maybe there is. (Sound confusing? Read on.) The problem is that pixels—short for picture elements—are basically dots on a rendering device, such as a monitor or (more loosely) on a printer. The number of pixels packed into an inch depends on lots of variables, such as the resolution of the output device as well as its size.

For instance, at the same resolution, the number of pixels in an inch on a 19-inch monitor will be different than the number on a 21-inch monitor. Why? Because the screen resolution is spread over a larger display surface, resulting in fewer pixels per inch of that display surface.

Now let's throw fonts into the mix. Different fonts pack different number of characters into a given linear measurement. You can see this most frequently if you put a bunch of text in a cell, copy the cell down a number of rows, and then apply different fonts to each cell. The contents of the cells will occupy a different horizontal space depending on the font (and point size) selected.

If you are using a monospace font (like Courier) which has a set size for all characters you can calculate the characters per inch for all characters and then, based on the number of characters, determine a rough estimate of the number of pixels. But, you still run into problems because you have to take the output device into consideration.

This will not work with proportionate fonts since the size of the characters vary for each character: Ms are much wider than Is for example. Therefore for each character of each font (and perhaps even each font size) one would need a table of pixel size and one would have to create a function to loop through the string and keep a running total of the sizes from each character. This gets even more complicated if various character attributes, such as bold or italic, or applied to the font.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (3802) applies to Microsoft Excel 97, 2000, 2002, and 2003.

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

Limits to Filtering

Excel limits the number of items that can be shown in an AutoFilter drop-down list. Granted, it is a high limit, but it ...

Discover More

First and Last Names in a Page Header

When you have a worksheet that includes a long list of names, you may want the first and last names on each page to ...

Discover More

Spell Checking Only Checking Grammar

Word has a built-in spelling and grammar checker that can help reduce errors in your prose. It may be a bit confusing if ...

Discover More

Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!

More ExcelTips (menu)

Using the Keyboard to Select and Resize a Chart Object

When working with charts and chart objects, Excel is very dependent on the mouse. If you don't want to use the mouse, but ...

Discover More

Adding Drop Shadows

Want your shapes to really "pop" off the page? Add a drop shadow to them, as described in this tip.

Discover More

Using a Graphic for a Background

If you want to enhance the appearance of a worksheet, one way to do it is to add a graphic. Excel allows you to add one ...

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}] (all 7 characters, in the sequence shown) 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 6 + 5?

There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)


This Site

Got a version of Excel that uses the menu interface (Excel 97, Excel 2000, Excel 2002, or Excel 2003)? This site is for you! If you use a later version of Excel, visit our ExcelTips site focusing on the ribbon 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.