
Tips.Net > WordTips Home > Tables > Finding a Cell Reference
Summary: Want to know what the reference address is for a particular cell in a table? Word won’t tell you, but you can use a macro to figure it out. (This tip works with Microsoft Word 97, Word 2000, Word 2002, Word 2003, and Word 2007.)
When you are working with tables, you often need to know the reference of a particular cell. For certain functions or fields, Word expects the cell reference to be specified using the Column/Row format that many readers are familiar with in Excel. For instance, A1 is the top-left cell, B1 is one cell to the right, and A2 is one cell below the first cell.
Unfortunately, there is no inherent capability of Word to inform you of the reference of a cell you have selected. You can get around this problem by using a macro. The following example macro will return, in the status bar, the current column and row in which the insertion point is located.
Sub CellRef()
Const clngAOffset As Long = 64
' Word's maximum columns is 64, but this procedure
' can cope up to clngMaxCols columns
Const clngMaxCols As Long = 702
Dim lngRow As Long, lngCol As Long
Dim strCol As String
' See if in table
If Selection.Information(wdWithInTable) Then
' Get column and row numbers
lngCol = Selection.Information(wdStartOfRangeColumnNumber)
lngRow = Selection.Information(wdStartOfRangeRowNumber)
' Convert column number to letter
Select Case lngCol
Case Is < 27
' Single character column reference
strCol = Chr$(clngAOffset + lngCol)
Case Is > clngMaxCols
MsgBox "Table is too big"
Exit Sub
Case Else
' Two-character column reference
strCol = Chr$(clngAOffset + Fix((lngCol - 1) / 26))
strCol = strCol & Chr$(CLng(clngAOffset + 1 _
+ ((lngCol - 1) Mod 26)))
End Select
' Show column, row, and cell reference in status bar
StatusBar = "Col:" & lngCol & "/Row:" & lngRow _
& " = Cellref: " & strCol & CStr(lngRow)
End If
End Sub
When you run the macro, it displays the requested information on the status bar in the following format:
Col:2/Row:1 = B1
You should note that the macro will handle tables that have more dimensions that Word will natively handle. This was not arbitrarily done; programmatically it is just as easy to return the 702nd column of a table (ZZ) as it is to return the 64th column (BL). (Word is limited to only 64 columns in a table.)
If you are still using Word 97, then you should know that there is a different approach you can take. Microsoft was kind enough to include a macro that you can use, if desired. This macro is called TableCellHelper, and it is in the Macros8.dot template provided on your original Word 97 (or Office 97) CD-ROM. It may even be installed on your system already; you can use the Find feature of Windows to locate the file and then use Word's Organizer to transfer TableCellHelper to your Normal.dot template.
When you run TableCellHelper, it installs itself on the standard toolbar. When you position the insertion pointer in a table cell and then run the macro, it displays a message box that shows the cell reference of the current cell, along with the overall size of the table.
Tip #1358 applies to Microsoft Word versions: 97 2000 2002 2003 2007
Create and Merge! Discover how to use Word's mail merge tool to create your own custom documents. WordTips: Mail Merge Magic includes all the information you need to make your merges more productive.
Learn to search for and replace text, formatting, graphics, and special characters the easy way with WordTips: Find and Replace. (more information...)
Ask a Word Question
Make a Comment
Beauty Tips
Bugs and Pests Tips
Car Tips
Cleaning Tips
College Tips
Cooking Tips
Excel2007 Tips
ExcelTips
Family Tips
Gardening Tips
Health Tips
Home Tips
Money Tips
Organizing Tips
Pet Tips
Word2007 Tips
WordTips